1 class Singleton(object): 2 def __new__(cls, *args, **kwargs): 3 if ‘_inst‘ not in vars(cls): 4 cls._inst = super(Singleton, cls).__new__(cls, *args, **kwargs) 5 return cls._inst 6 7 def __init__(self): 8 print "init" 9 10 11 class SingleSpam(Singleton): 12 def __init__(self, s): 13 self.s = s 14 print "creat"
时间: 2024-10-25 02:21:38