Skip to content

Instantly share code, notes, and snippets.

@shelling
Last active March 18, 2018 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shelling/512d5dbd0dd75f0d80ceed0b44e43472 to your computer and use it in GitHub Desktop.
Save shelling/512d5dbd0dd75f0d80ceed0b44e43472 to your computer and use it in GitHub Desktop.
class Singleton(object):
def __new__(cls):
if not cls.singleton:
cls.singleton = object.__new__(cls)
return cls.singleton
class Foo(Singleton):
singleton = None
pass
class Bar(object):
pass
f1 = Foo()
f2 = Foo()
print(f1 == f2)
print(f1)
print(f2)
b1 = Bar()
b2 = Bar()
print(b1 == b2)
print(b1)
print(b2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment