Skip to content

Instantly share code, notes, and snippets.

@Hammer2900
Created September 21, 2015 09:43
Show Gist options
  • Select an option

  • Save Hammer2900/b0ea88ac37ac4a6b994c to your computer and use it in GitHub Desktop.

Select an option

Save Hammer2900/b0ea88ac37ac4a6b994c to your computer and use it in GitHub Desktop.
Singelton
def singleton(cls):
obj = cls()
# Always return the same object
cls.__new__ = staticmethod(lambda cls: obj)
# Disable __init__
try:
del cls.__init__
except AttributeError:
pass
return cls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment