Generic singleton

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Mar 5 08:33:44 CET 2010


mk wrote:

> Or I could make my life simpler and use global variable. :-)

Indeed. You actually *have* a global variable already, you've
just hidden it inside another object. That doesn't make it any
less global, though.

If you want to defer creation of the object until the first
time it's used, use a function that creates an instance the
first time it's called. Your Singleton class is really just
an overly elaborate way of implementing such a function.

-- 
Greg



More information about the Python-list mailing list