Newbie: anything resembling static?

Erik Max Francis max at alcyone.com
Wed Jan 29 22:03:42 EST 2003


anton wilson wrote:

> Is there any way of imitating "static" C function variables without
> having to
> define the variable as a global? I just want persistent function
> variables
> but i want them to be local to the function namespace. :S

Not explicitly.  You can use a global but prefix it with an underscore
(a convention in Python that says "hands off").  You could also include
an additional argument with a (mutable) default value which you don't
mention in your API and use it that way, but I personally would
discourage that idiom for this usage since I find it to be a little
unclear.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ The work will teach you how to do it.
\__/ (an Estonian proverb)
    Python chess module / http://www.alcyone.com/pyos/chess/
 A chess game adjudicator in Python.




More information about the Python-list mailing list