Skip to content

Instantly share code, notes, and snippets.

@adh
Created November 24, 2010 22:34
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 adh/714556 to your computer and use it in GitHub Desktop.
Save adh/714556 to your computer and use it in GitHub Desktop.
>>> def singleton(klass):
... inst = klass()
... return lambda:inst
...
>>> @singleton
... class Bar:
... pass
...
>>> Bar()
<__main__.Bar instance at 0x7fea76c054d0>
>>> Bar()
<__main__.Bar instance at 0x7fea76c054d0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment