an example of a singleton design pattern in python?

Ville Vainio ville.spamstermeister.vainio at thisisspamprotectiontut.finland
Wed Jan 21 02:38:35 EST 2004


    >>  This trivial snippet might be enough for your needs:
    >> 
    >> class Foo(): pass
    >> 
    >> _inst = None
    >> 
    >> def fooinstance(): if not _inst: _inst = Foo() return _inst

    peter> Looks like at least two errors, one being the parentheses
    peter> on the class name, and the other being a failure to flag
    peter> _inst as being global...

True. I guess the idea got through anyway. It was late :-P.

-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list