an example of a singleton design pattern in python?
Peter Hansen
peter at engcorp.com
Tue Jan 20 17:45:03 EST 2004
Ville Vainio wrote:
>
> >>>>> "Daniel" == Daniel Ortmann <dortmann at lsil.com> writes:
>
> Daniel> Hello, Does anyone have an example of a singleton design
> Daniel> pattern in python?
>
> This trivial snippet might be enough for your needs:
>
> class Foo():
> pass
>
> _inst = None
>
> def fooinstance():
> if not _inst:
> _inst = Foo()
> return _inst
Looks like at least two errors, one being the parentheses on the
class name, and the other being a failure to flag _inst as being
global...
-Peter
More information about the Python-list
mailing list