Skip to content

Instantly share code, notes, and snippets.

@saivenkat
Created December 4, 2009 03:16
Show Gist options
  • Select an option

  • Save saivenkat/248802 to your computer and use it in GitHub Desktop.

Select an option

Save saivenkat/248802 to your computer and use it in GitHub Desktop.
Singleton Pattern in Python
class HTTPClient(object):
_inst = None
def __new__(cls):
if cls._inst:
return cls._inst
else:
o = super(HTTPClient, cls).__new__(cls)
cls._inst = o
return o
if __name__ == '__main__' :
obj1 = HTTPClient()
obj2 = HTTPClient()
assert(obj1, obj2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment