Static Variables
Gerhard Häring
gerhard at bigfoot.de
Tue Apr 2 23:17:57 EST 2002
Gerhard Häring wrote in comp.lang.python:
> Jim Jacobs wrote in comp.lang.python:
>> Is it possible to simulate "C" style static variables in functions?
>
> No.
>
>> In methods?
>
> No.
Stupid me, sure you can: just assign attributes to the
functions/methods, like in:
def foo():
foo.this_is_a_static_var = 5
You can access the function/method attributes from anywhere.
But I really can't see a good reason to actually use this feature.
Gerhard
--
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20 A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
More information about the Python-list
mailing list