Created
February 22, 2016 15:37
-
-
Save mcihad/0c87962ea76c4c82822e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def singleton(class_): | |
instances = {} | |
def getinstance(*args, **kwargs): | |
if class_ not in instances: | |
instances[class_] = class_(*args, **kwargs) | |
return instances[class_] | |
return getinstance | |
@singleton | |
class MyClass(BaseClass): | |
pass | |
#http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment