Created
July 9, 2013 13:39
-
-
Save AndrewDowning/5957432 to your computer and use it in GitHub Desktop.
Most trivial Singleton in Python
This file contains 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 __init__(self, thing): | |
global Singleton | |
Singleton = self | |
self.thing = thing | |
def __call__(self, thing): | |
return self | |
singleton = Singleton("Original Instance") # This could happen anywhere | |
new_instance_attempt = Singleton("Subsequent instance will just be the original") | |
print(new_instance_attempt.thing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment