Python Design Patterns (was Re: Should I learn Python or Java?)
Fredrik Lundh
fredrik at effbot.org
Fri Jan 12 02:39:26 EST 2001
Daniel Klein wrote:
> Since you mention it, what is the pythonic way to implement a Singleton?
alternative 1: create exactly one instance when initializing
a module, and store the instance in the module namespace
alternative 2: same, but use a factory function to create
the object when it's first asked for.
any other attempts to implement singletons are unpythonic.
> You don't have to provide a complete answer, just a pointer as to where to
> start would be fine as I like to try to work these things out at first for myself.
see
www.deja.com => "singleton ~g comp.lang.python"
for more background.
Cheers /F
More information about the Python-list
mailing list