Skip to content

Instantly share code, notes, and snippets.

@elben
Created April 26, 2010 17:16
Show Gist options
  • Save elben/379602 to your computer and use it in GitHub Desktop.
Save elben/379602 to your computer and use it in GitHub Desktop.
class Singleton(object):
def __new__(cls, *p, **k):
if not '_the_instance' in cls.__dict__:
cls._the_instance = object.__new__(cls)
return cls._the_instance
class Test(Singleton):
def __init__(self):
pass
assert Test() is Test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment