Last active
March 18, 2018 05:34
-
-
Save shelling/512d5dbd0dd75f0d80ceed0b44e43472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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