How to initialize a class variable once

Roy Smith roy at
Tue Dec 9 05:08:04 CET 2008

I've got a class with a class variable:

class Foo:
   _map = {}

How do I make sure this only gets initialized the *first* time the
module containing the class is imported?  What appears to be happening
as it stands is each time the module gets imported, Foo._map get re-

More information about the Python-list mailing list