static variables in Python?

Rhamphoryncus rhamph at gmail.com
Wed Jul 30 13:51:00 EDT 2008


On Jul 29, 2:40 pm, kj <so... at 987jk.com.invalid> wrote:
> Yet another noob question...
>
> Is there a way to mimic C's static variables in Python?  Or something
> like it?  The idea is to equip a given function with a set of
> constants that belong only to it, so as not to clutter the global
> namespace with variables that are not needed elsewhere.

I'd go ahead and use globals.  If these really are constant you should
just name them clearly (and possibly use all caps).

If they have a possibility of becoming non-constant in the future,
write a class.  No fancy tricks needed to store state.



More information about the Python-list mailing list