Skip to content

Instantly share code, notes, and snippets.

@Nurdok
Created April 26, 2012 15:08
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 Nurdok/2500259 to your computer and use it in GitHub Desktop.
Save Nurdok/2500259 to your computer and use it in GitHub Desktop.
Singleton Implementation in Python Using Metaclasses
class SingletonType(type):
def __call__(cls, *args, **kwargs):
try:
return cls.__instance
except AttributeError:
cls.__instance = super(SingletonType, cls).__call__(*args, **kwargs)
return cls.__instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment