Skip to content

Instantly share code, notes, and snippets.

@AndrewDowning
Created July 9, 2013 13:39
Show Gist options
  • Save AndrewDowning/5957432 to your computer and use it in GitHub Desktop.
Save AndrewDowning/5957432 to your computer and use it in GitHub Desktop.
Most trivial Singleton in Python
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