Created
March 30, 2013 23:26
-
-
Save 1st/5278802 to your computer and use it in GitHub Desktop.
Singleton implantation on Python
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
class Singleton(type): | |
def __call__(self, *args, **kwargs): | |
if 'instance' not in self.__dict__: | |
self.instance = super(Singleton, self).__call__(*args, **kwargs) | |
return self.instance | |
class CoolFeautre(object): | |
__metaclass__ = Singleton | |
print CoolFeautre() | |
print CoolFeautre() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment