Static Variables
Peter Hansen
peter at engcorp.com
Tue Apr 2 23:06:40 EST 2002
Jim Jacobs wrote:
>
> Is it possible to simulate "C" style static variables in functions? In
> methods?
Maybe ... what do you mean by simulate, and what characteristics
of the C statics would you like to have?
In C, static inside a function causes the variable to be assigned
in the heap rather than on the stack (to put it one way) and
that gives the variable persistence across invocations of
the function (but scope local to the function).
In Python, you would use either an instance variable, inside
a method of an object, or the answer would be "no, but can
you get by with using 'global'?".
-Peter
More information about the Python-list
mailing list