Re: decorator to fetch arguments from global objects

2013-06-19 Thread Terry Reedy
On 6/19/2013 4:03 AM, Wolfgang Maier wrote: Wolfgang Maier biologie.uni-freiburg.de> writes: andrea crotti gmail.com> writes: 2013/6/18 Terry Reedy udel.edu> Decorators are only worthwhile if used repeatedly. What you specified can easily be written, for instance, as def save_doc(db=No

Re: decorator to fetch arguments from global objects

2013-06-19 Thread Wolfgang Maier
Wolfgang Maier biologie.uni-freiburg.de> writes: > > andrea crotti gmail.com> writes: > > > 2013/6/18 Terry Reedy udel.edu> > > > > Decorators are only worthwhile if used repeatedly. What you specified can > easily be written, for instance, as > > def save_doc(db=None): > >   if db is None:

Re: decorator to fetch arguments from global objects

2013-06-19 Thread Wolfgang Maier
andrea crotti gmail.com> writes: > > 2013/6/18 Terry Reedy udel.edu> > On 6/18/2013 5:47 AM, andrea crotti wrote: > Using a CouchDB server we have a different database object potentially > for every request. > We already set that db in the request object to make it easy to pass it > around for

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Steven D'Aprano
On Tue, 18 Jun 2013 10:47:57 +0100, andrea crotti wrote: > Using a CouchDB server we have a different database object potentially > for every request. > > We already set that db in the request object to make it easy to pass it > around form our django app, however it would be nice if I could set

Re: decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
2013/6/18 Terry Reedy > On 6/18/2013 5:47 AM, andrea crotti wrote: > >> Using a CouchDB server we have a different database object potentially >> for every request. >> >> We already set that db in the request object to make it easy to pass it >> around form our django app, however it would be nic

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Terry Reedy
On 6/18/2013 5:47 AM, andrea crotti wrote: Using a CouchDB server we have a different database object potentially for every request. We already set that db in the request object to make it easy to pass it around form our django app, however it would be nice if I could set it once in the API and

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Wolfgang Maier
andrea crotti gmail.com> writes: > > 2013/6/18 Wolfgang Maier biologie.uni-freiburg.de> > > > andrea crotti gmail.com> writes: > > > > > > Using a CouchDB server we have a different database object potentially for > every request. > > > > We already set that db in the request object to make

Re: decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
2013/6/18 Wolfgang Maier > andrea crotti gmail.com> writes: > > > > > > > Using a CouchDB server we have a different database object potentially > for > every request. > > > > We already set that db in the request object to make it easy to pass it > around form our django app, however it would b

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Wolfgang Maier
andrea crotti gmail.com> writes: > > > Using a CouchDB server we have a different database object potentially for every request. > > We already set that db in the request object to make it easy to pass it around form our django app, however it would be nice if I could set it once in the API an

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Fábio Santos
On Tue, Jun 18, 2013 at 10:47 AM, andrea crotti wrote: > def with_optional_db(func): > """Decorator that sets the database to the global current one if > not passed in or if passed in and None > """ > @wraps(func) > def _with_optional_db(*args, **kwargs): > func_args = func.func_code.co_varnames >

decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
Using a CouchDB server we have a different database object potentially for every request. We already set that db in the request object to make it easy to pass it around form our django app, however it would be nice if I could set it once in the API and automatically fetch it from there. Basically

Re: Global Objects...

2006-08-16 Thread Dan
KraftDiner wrote: > I have a question.. > > myGlobalDictionary = dictionary() > > > class someClass: >def __init__(self): > self.x = 0; >def getValue(self, v) > myGlobalDictionary.getVal(v) > > > myGlobalDictionary doesn't seem to be visible to my someClass methods. > Why?

Re: Global Objects...

2006-08-16 Thread Chaz Ginger
KraftDiner wrote: > I have a question.. > > myGlobalDictionary = dictionary() > > > class someClass: >def __init__(self): > self.x = 0; >def getValue(self, v) > myGlobalDictionary.getVal(v) > > > myGlobalDictionary doesn't seem to be visible to my someClass methods. > Why?

Re: Global Objects...

2006-08-15 Thread Erik Max Francis
KraftDiner wrote: > myGlobalDictionary doesn't seem to be visible to my someClass methods. > Why? What should I do? Specify more clearly what is happening, what you wanted it to do, and why you think it's wrong? You haven't given enough information. -- Erik Max Francis && [EMAIL PROTECTED] &

Global Objects...

2006-08-15 Thread KraftDiner
I have a question.. myGlobalDictionary = dictionary() class someClass: def __init__(self): self.x = 0; def getValue(self, v) myGlobalDictionary.getVal(v) myGlobalDictionary doesn't seem to be visible to my someClass methods. Why? What should I do? -- http://mail.python.org

Re: How to have application-wide global objects

2006-07-14 Thread Jeremy Sanders
Fredrik Lundh wrote: > no, the "bar.py" *file* gets loaded twice, first as the "foo.bar" > module, and then as the "bar" module. True and I agree with your email, but suppose there is bar1.py and bar2.py in foo, then they can refer to each other by importing bar2 and bar1, respectively. These mod

Re: How to have application-wide global objects

2006-07-14 Thread Fredrik Lundh
Jeremy Sanders wrote: >> if you got some other result, you didn't just import the same thing >> twice... > > I think you may be incorrect, or I have misinterpreted you. you've misinterpreted what Python means by "a module". > Try this: > import foo.bar here you import the module named "foo.ba

Re: How to have application-wide global objects

2006-07-14 Thread Jeremy Sanders
Fredrik Lundh wrote: > if you got some other result, you didn't just import the same thing > twice... I think you may be incorrect, or I have misinterpreted you. Try this: ** In test.py import sys import foo.bar print foo.bar.myvar foo.bar.myvar = 42 print foo.bar.myvar

Re: How to have application-wide global objects

2006-07-13 Thread Sanjay
Got crystal clear. Thanks a lot to all for the elaborated replies. Sanjay -- http://mail.python.org/mailman/listinfo/python-list

Re: How to have application-wide global objects

2006-07-13 Thread Fredrik Lundh
Jeremy Sanders wrote: >> "import" doesn't create new objects, so that's not very likely. can you >> post some code so we don't have to guess what you've tried and not ? > > It does if you mess around with sys.path between doing two imports of the > same thing (at least I found out the hard way o

Re: How to have application-wide global objects

2006-07-13 Thread Jeremy Sanders
Fredrik Lundh wrote: > "Sanjay" wrote: > >> Trying hard, I am not even being able to figure out how to create an >> object in one module and refer the same in another one. "import" >> created a new object, as I tried. > > "import" doesn't create new objects, so that's not very likely. can you >

Re: How to have application-wide global objects

2006-07-13 Thread Bruno Desthuilliers
Sanjay wrote: > Hi Bruno, > > Thanks a lot for the reply. In order to post here, I wrote a very > simple program now, and it seems working! I can diagnose the original > problem now. Fine. > There might be some other problem. This, we can't tell, since you didn't post the code !-) > Pardon me

Re: How to have application-wide global objects

2006-07-13 Thread zarrg
Sanjay wrote: > Probably a newcomer question, but I could not find a solution. > > I am trying to have some singleton global objects like "database > connection" or "session" shared application wide. > > Trying hard, I am not even being able to figure out h

Re: How to have application-wide global objects

2006-07-13 Thread Sanjay
: "(at the module's to level)" Thanks Sanjay -- Bruno Desthuilliers wrote: > Sanjay wrote: > > Probably a newcomer question, but I could not find a solution. > > > > I am trying to have some sin

Re: How to have application-wide global objects

2006-07-13 Thread Fredrik Lundh
"Sanjay" wrote: > Trying hard, I am not even being able to figure out how to create an > object in one module and refer the same in another one. "import" > created a new object, as I tried. "import" doesn't create new objects, so that's not very likely. can you post some code so we don't have to

Re: How to have application-wide global objects

2006-07-13 Thread Bruno Desthuilliers
Sanjay wrote: > Probably a newcomer question, but I could not find a solution. > > I am trying to have some singleton global objects like "database > connection" or "session" shared application wide. Whenever possible, dont. If you really have no other way out

How to have application-wide global objects

2006-07-13 Thread Sanjay
Probably a newcomer question, but I could not find a solution. I am trying to have some singleton global objects like "database connection" or "session" shared application wide. Trying hard, I am not even being able to figure out how to create an object in one module a