which is best for a singleton, module or class?

Peter Hansen peter at engcorp.com
Thu Nov 29 06:38:11 CET 2001


Peter Bismuti wrote:
> 
> What is best for a singleton, making it a module or a class within a module?
> I guess the reason why having a class within a module undesirable is that it
> adds to the namespace of the object mymodule.mclass.property instead of
> mymodule.property, and so fourth.  I know you can import it in a way to
> reduce the path length of the object, but still, it seems like a cleaner
> coding style to just use the module itself.   Opinions? THanks.

See http://www.google.com/search?q=python+singleton , especially the 
second item (Alex's Borg pattern).

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list