Singleton across modules
问题 I'm trying to implement a Singleton and I am running into difficulty when I import the module. My set up is the following. I am using Python 2.7. MODULE 1 class SingletonClass(object): def __new__(self, *args, **kwargs): if not self._instance: self._instance = super(SingletonClass, self).__new__( self, *args, **kwargs) return self._instance print SingletonClass() #OUTPUT: 0x00000000030F1630 print SingletonClass() #OUTPUT: 0x00000000030F1630 (Good, what I want) MODULE 2 import SingletonClass