Static Variables

Hamish Lawson hamish_lawson at yahoo.co.uk
Wed Apr 3 04:17:03 EST 2002


Peter Hansen wrote:

> 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 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'?".

If the requirement is to be able to get a different result for each
call of the function, then a generator might be the answer.

Hamish Lawson



More information about the Python-list mailing list