C-style static variables in Python?

Patrick Maupin pmaupin at gmail.com
Sun Apr 4 16:35:54 EDT 2010

On Apr 4, 1:57 pm, John Nagle <na... at animats.com> wrote:
>     If you want functions with state, use an object. That's what they're
> for.  Don't muck with the internal representation of functions.

While "Don't muck with the internal representation of functions" is
excellent advice over 99% of the time, it is also true that it is
often possible, sometimes even encouraged, to have "functions with

This is done without "mucking" and without explicitly declaring a
class or a class instance.  See, e.g. closures and generator


More information about the Python-list mailing list