[Tutor] singleton pattern
alan.gauld@bt.com
alan.gauld@bt.com
Thu, 17 May 2001 18:45:55 +0100
> How about trying not to fake out the mechanisms and just using Python
> classes?
>
> class SingletonInstance:
> instance = None # class member for the singleton instance
> def __init__(self, klass):
> if self.__class__.instance is None:
Hmm, I need to do some digging. I've never played with
Python's object model at that level...
Alan G.
> Guido once also suggested that replacing __class__ (which is
> something I believe Alan was attempting to do)
I wasn't replacing class just returning a pointer to the
original instance as an attribute of the Exception.
But the magic methods might provide a better solution,
I'll take a look over the weekend.
Alan G.