[Tutor] Re: C-like local static var in Py ?

Bob Gailer ramrom@earthling.net
Sun Dec 1 21:57:03 2002


At 08:47 PM 12/1/2002 -0500, Derrick 'dman' Hudson wrote:
>A function by itself has no permanent state.

Oh, yeah? Try this:

 >>> def inc():
...     if inc.__dict__.has_key('a'):
...             inc.__dict__['a'] += 1
...     else:
...             inc.__dict__['a'] = 1
...     print inc.__dict__['a']
 >>> inc()
1
 >>> inc()
2
 >>> inc.a
2
 >>> inc.a = 0
 >>> inc()
1


Bob Gailer
mailto:ramrom@earthling.net
303 442 2625