Pythonic way to do static local variables?
Terry Reedy
tjreedy at udel.edu
Tue Apr 26 13:15:00 EDT 2005
"Charles Krug" <cdkrug at worldnet.att.net> wrote in message
news:7Ujbe.647694$w62.444038 at bgtnsc05-news.ops.worldnet.att.net...
> Both of these techniques look promising here.
Here a third, the closure approach (obviously not directly tested):
def func_with_static(datalist):
def real_func(otherargs):
<code that uses datalist>
return real_func
func1 = func_with_static([.1, 99, 1e-10,...])
If needed, real_func can *modify* (but not *rebind*) datalist.
Unlike the attribute approach, but like the class approach, you can
simultaneously have have multiple closures with different static data
func2 = func_with_static([.2, 152, 1e-9, ...])
Terry J. Reedy
More information about the Python-list
mailing list