Newbie: anything resembling static?
Rene Pijlman
reageer.in at de.nieuwsgroep
Tue Feb 11 16:08:31 EST 2003
Phil Rittenhouse:
[static variable in function]
>If you wrapped it in a class, you'd have to take care of creating the object
>before anyone calls it and sharing that object around somehow so everyone
>can access it. It seems like a lot of complexity for what is supposed
>to be a very simple task.
Yes. Guido's answer was that you should simply make it a
module-global variable:
"In that case, consider using a module-global variable, e.g.:
ncalls = 0
def myfunction(arg):
global ncalls
ncalls = ncalls + 1
...your code goes here...
Because Python's globals are module-global, not program-global,
this is generally a safe practice."
http://groups.google.com/groups?q=static+group:comp.lang.python+author:guido&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=199806221337.JAA03354%40eric.CNRI.Reston.Va.US&rnum=4
--
René Pijlman
Wat wil jij leren? http://www.leren.nl
More information about the Python-list
mailing list