singleton objects with decorators
Michele Simionato
michele.simionato at gmail.com
Tue Apr 12 12:51:19 EDT 2005
Uhm? If I pass different parameters I want to have
different instances. The Singleton behaviour is recovered
only when I pass always the same arguments, in
particular when I pass 0-arguments:
>>> class Foobar:
... __metaclass__ = Memoize
...
>>> Foobar()
<__main__.Foobar object at 0xb7defbcc>
>>> Foobar()
<__main__.Foobar object at 0xb7defbcc>
>>> Foobar()
<__main__.Foobar object at 0xb7defbcc>
Of course if for Singleton you mean "whatever I pass
to the constructor it must always return the same
instance" then this pattern is not a Singleton.
This is why I call it memoize ;)
More information about the Python-list
mailing list