Created
April 26, 2012 15:08
-
-
Save Nurdok/2500259 to your computer and use it in GitHub Desktop.
Singleton Implementation in Python Using Metaclasses
This file contains 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
class SingletonType(type): | |
def __call__(cls, *args, **kwargs): | |
try: | |
return cls.__instance | |
except AttributeError: | |
cls.__instance = super(SingletonType, cls).__call__(*args, **kwargs) | |
return cls.__instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment