Skip to content

Instantly share code, notes, and snippets.

@maksymx
Forked from shelling/singleton.py
Last active August 29, 2015 14:22
Show Gist options
  • Save maksymx/dab9868edaf93849feee to your computer and use it in GitHub Desktop.
Save maksymx/dab9868edaf93849feee to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
class Hello(object):
singleton = None
def __new__(clz):
if not clz.singleton:
clz.singleton = object.__new__(clz)
return clz.singleton
def __init__(self):
self.world = "world"
return None
h = Hello()
h.hello = "hello"
print h.hello
print h
print h.world
x = Hello()
print x.hello
print x
print x.world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment