Skip to content

Instantly share code, notes, and snippets.

@tanelpuhu
Created February 21, 2011 09:29
Show Gist options
  • Save tanelpuhu/836853 to your computer and use it in GitHub Desktop.
Save tanelpuhu/836853 to your computer and use it in GitHub Desktop.
class Singleton:
__single = None
def __init__( self ):
if Singleton.__single:
raise Singleton.__single
Singleton.__single = self
def Handle(x = Singleton):
try:
single = x()
except Singleton, s:
single = s
return single
assert(Handle() == Handle())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment