Python singleton pattern
Posted
by Javier Garcia
on Stack Overflow
See other posts from Stack Overflow
or by Javier Garcia
Published on 2010-06-14T14:11:01Z
Indexed on
2010/06/14
14:22 UTC
Read the original article
Hit count: 289
Hi,
someone can tell me why this is incorrect as a singleton pattern:
class preSingleton(object):
def __call__(self):
return self
singleton = preSingleton()
a = singleton()
b = singleton()
print a==b
a.var_in_a = 100
b.var_in_b = 'hello'
print a.var_in_b
print b.var_in_a
Edit: The above code prints:
True
hello
100
thank you very much
© Stack Overflow or respective owner