Is there a way to find what function called the current function? So for example:
def first():
second()
def second():
# print out here what function called this one
Any ideas?
I use ZODB and i want to copy my 'database_1.fs' file to another 'database_2.fs',
so I opened the root dictionary of that 'database_1.fs' and I (pickle.dump) it in a text file.
Then I (pickle.load) it in a dictionary-variable, in the end I update the root dictionary of the other 'database_2.fs' with the dictionary-variable.
It works, but I wonder why the size of the 'database_1.fs' not equal to the size of the other 'database_2.fs'.
They are still copies of each other.
def openstorage(store): #opens the database
data={}
data['file']=filestorage
data['db']=DB(data['file'])
data['conn']=data['db'].open()
data['root']=data['conn'].root()
return data
def getroot(dicty):
return dicty['root']
def closestorage(dicty): #close the database after Saving
transaction.commit()
dicty['file'].close()
dicty['db'].close()
dicty['conn'].close()
transaction.get().abort()
then that's what i do:-
import pickle
loc1='G:\\database_1.fs'
op1=openstorage(loc1)
root1=getroot(op1)
loc2='G:database_2.fs'
op2=openstorage(loc2)
root2=getroot(op2)
>>> len(root1)
215
>>> len(root2)
0
pickle.dump( root1, open( "save.txt", "wb" ))
item=pickle.load( open( "save.txt", "rb" ) ) #now item is a dictionary
root2.update(item)
closestorage(op1)
closestorage(op2)
#after I open both of the databases
#I get the same keys in both databases
#But `database_2.fs` is smaller that `database_2.fs` in size I mean.
>>> len(root2)==len(root1)==215 #they have the same keys
True
Note:
(1) there are persistent dictionaries and lists in the original database_1.fs
(2) both of them have the same length and the same indexes.
Hi I m following the tutorial on http://docs.djangoproject.com/en/dev/intro/tutorial02/#intro-tutorial02 in windows 7 envoirement. my settings file is
TEMPLATE_DIRS = (
'C:/django-project/myapp/mytemplates/admin'
)
i got the base_template from the template admin/base_site.html from within the default Django admin template directory in the source code of Django itself (django/contrib/admin/templates) into an admin subdirectory of myapp directory as the tutorial instructed.
It doesn't seem to take affect for some reason. Any clue of what might be the problem? Do i have to do a sync db ?
Hello,
I'm making a toolbar using wxpython and I want to put the Quit button on the right side of it, I don't want to put them sequencially.
Is it possible to define this position?
Thanks in advance!
If I want to split a list of words separated by a delimiter character, I can use
>>> 'abc,foo,bar'.split(',')
['abc', 'foo', 'bar']
But how to easily and quickly do the same thing if I also want to handle quoted-strings which can contain the delimiter character ?
In: 'abc,"a string, with a comma","another, one"'
Out: ['abc', 'a string, with a comma', 'another, one']
Related question: How can i parse a comma delimited string into a list (caveat)?
I´m (professionally) creating a SQL Server database client by using Visual Studio 2008, C# - Windows Form(s). And I´m using all the built in stuff, provided by my friend VS Studio, dragging and dropping, creating SQL query tables in DataSet.xsd, and so on... I like that.
But!
I would like to try out LINQ, as I would like to have something that to me is more intuitive than pure SQL...
And (here comes the newbie-problem to be solved)!
I don´t know where to put the LINQ code to make a table "pop up" in the Data Sources window - meaning I´m completely stuck! How should I do it?
I want a script to start and interact with a long running process. The process is started first time the script is executed, after that the script can be executed repeatedly, but will detect that the process is already running. The script should be able to interact with the process. I would like this to work on Unix and Windows.
I am unsure how I do this. Specifically how do I detect if the process is already running and open a pipe to it? Should I use sockets (e.g. registering the server process on a known port and then check if it responds) or should I use "named pipes"? Or is there some easier way?
My company recently upgraded from IE 6 to IE 8. My site does not render properly. I wanted to make sure my .net version was fixed before I started to try to fix a problem. I think my web.config file says i'm using 3.5, but if I get an error when running the app I get this:
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
Why does it say 2.0? rather than 3.5? How do i change this?
(using visual studio 2008, running the site locally)
Thanks in advance!
Hi there.
I'm setting up a VC++ project in MS Visual Studio 2008 that'll be used by several people. I wanted to keep things as simple as possible so I've set up Additional Include Directories via the Project properties. I've also set up additional library files via Tools - Options - Projects and Solutions - VC++ Directories.
However, my issue is that I really need to set up Additional library PATHs, because I am using an SDK which does inline linking of libraries.
I could just tell each one of the participants to manually add the library path to their MSVS2008 environment, but it would be handy if I could integrate the RELATIVE library path in the project itself.
I'm using pyPEG to create a parse tree for a simple grammar. The tree is represented using lists and tuples. Here's an example:
[('command',
[('directives',
[('directive',
[('name', 'retrieve')]),
('directive',
[('name', 'commit')])]),
('filename',
[('name', 'f30502')])])]
My question is what do I do with it at this point? I know a lot depends on what I am trying to do, but I haven't been able to find much about consuming/using parse trees, only creating them. Does anyone have any pointers to references I might use?
Thanks for your help.
i have file with contents in list form such as
[1,'ab','fgf','ssd']
[2,'eb','ghf','hhsd']
[3,'ag','rtf','ssfdd']
i want to read that file line by line using f.readline and assign thn to a list so as to use it is the prog as a list for using list properties
tried like
k=[ ]
k=f.readline()
print k[1]
i xpected a result to show 2nd element in the list in first line
but it showed the first bit and gave o/p as '1'
how to get the xpected output..
please suggest
Hi !
I'm working with web2py and for some reason web2py seems to fail to notice when code has changed in certain cases. I can't really narrow it down, but from time to time changes in the code are not reflected, web2py obviously has the old version cached somewhere.
The only thing that helps is quitting web2py and restarting it (i'm using the internal server).
Any hints ? Thank you !
Hi,
I am new to numpy. Am wonder is there a way to do lookup of two ndarray of different shapes?
for example, i have 2 ndarrays as below:
X = array([[0, 3, 6],
[3, 3, 3],
[6, 0, 3]])
Y = array([[0, 100],
[3, 500],
[6, 800]])
and would like to lookup each element of X in Y, then be able to return the second column of Y:
Z = array([[100, 500, 800],
[500, 500, 500],
[800, 100, 500]])
thanks, fahhean
I have a table with an 'expires' datetime column. I want to find all the items that have an 'expires' date earlier than now.
I've tried
session.query(Item).filter(Item.expires < now())
but it doesn't return anything regardless of the dates in the table.
I'm using PostgreSQL 8.4.
How do I do this comparison?
Hey,
I'm running a function which evaluates commands passed in using stdin and another function which runs a bunch of jobs. I need to make the latter function sleep at regular intervals but that seems to be blocking the stdin. Any advice on how to resolve this would be appreciated.
The source code for the functions is
def runJobs(comps, jobQueue, numRunning, limit, lock):
while len(jobQueue) >= 0:
print(len(jobQueue));
if len(jobQueue) > 0:
comp, tasks = find_computer(comps, 0);
#do something
time.sleep(5);
def manageStdin():
print "Global Stdin Begins Now"
for line in fileinput.input():
try:
print(eval(line));
except Exception, e:
print e;
--Thanks
Does anyone know Twitter's rate limit on posting? Looking at their web page they claimed to not have one but I get an exception thrown if my program posts too fast... Any help is appreciated.
I have a table, Foo. I run a query on Foo to get the ids from a subset of Foo. I then want to run a more complicated set of queries, but only on those IDs. Is there an efficient way to do this? The best I can think of is creating a query such as:
SELECT ... --complicated stuff
WHERE ... --more stuff
AND id IN (1, 2, 3, 9, 413, 4324, ..., 939393)
That is, I construct a huge "IN" clause. Is this efficient? Is there a more efficient way of doing this, or is the only way to JOIN with the inital query that gets the IDs? If it helps, I'm using SQLObject to connect to a PostgreSQL database, and I have access to the cursor that executed the query to get all the IDs.
Is it possible to get the name of a node using minidom?
for example i have a node:
<heading><![CDATA[5 year]]></heading>
what i'm trying to do is store the value heading so that i can use it as a key in a dictionary,
the closest i can get is something like
[<DOM Element: heading at 0x11e6d28>]
i'm sure i'm overlooking something very simple here, thanks!
I have an ORM class called Person, which wraps around a person table:
After setting up the connection to the db etc, I run the ff statement.
people = session.query(Person).all()
The person table does not contain any data (as yet), so when I print the variable people, I
get an empty list.
I renamed the table referred to in my ORM class People, to people_foo (which does not exist).
I then run the script again. I was surprised that no exception was thrown when attempting to access a table that does not exist.
I therefore have the following 2 questions:
How may I setup SQLAlchemy so that it propagates db errors back to the script?
How may I view (i.e. print) the SQL that is being sent to the db engine
If it helps, I am using PostgreSQL as the db
I want to have a twisted service (started via twistd) which listens to TCP/POST request on a specified port on a specified IP address. By now I have a twisted application which listens to port 8040 on localhost. It is running fine, but I want it to only listen to a certain IP address, say 10.0.0.78.
How-to manage that? This is a snippet of my code:
application = service.Application('SMS_Inbound')
smsInbound = resource.Resource()
smsInbound.putChild('75sms_inbound',ReceiveSMS(application))
smsInboundServer = internet.TCPServer(8001, webserver.Site(smsInbound))
smsInboundServer.setName("SMS Handling")
smsInboundServer.setServiceParent(application)
import inspect
class Test:
def test(self, p, d={}):
d.update(p)
return d
print inspect.getargspec(getattr(Test, 'test'))[3]
print Test().test({'1':True})
print inspect.getargspec(getattr(Test, 'test'))[3]
I would expect the argspec for Test.test not to change but because of dict.update it does. Why?
class a(object):
c=b()# how to call the b method
d=4
def __init__(self):
print self.c
def b(self):
return self.d+1
a()
how to call the 'b' method not in the __init__
thanks
the error is :
Traceback (most recent call last):
File "D:\zjm_code\a.py", line 12, in <module>
class a(object):
File "D:\zjm_code\a.py", line 13, in a
c=b()# how to call the b method
NameError: name 'b' is not defined