class Singleton(object):
def __new__(cls,*args,**kwargs):
if not hasattr(cls,‘_inst‘):
cls._inst=super(Singleton,cls).__new__(cls,*args,**kwargs)
return cls._inst
class A(Singleton):
def __init__(self,s):
self.s = s
a = A(‘test‘)
print dir(a)
b = A(‘test1‘)
print id(a),a.s
print id(b),b.s
class a(object):
def __init__(self,msg):
self.msg = msg
def send(self):
print (‘send to %s‘%self.msg)
class b(object):
def __init__(self,msg):
self.msg=msg
def send(self):
print (‘send to vadieo %s‘%self.msg)
class ab(a,b):
def __init__(self,paramater):
super(ab).__init__
self.paramater = paramater
if self.paramater == ‘a‘:
a.send()
elif self.paramater == ‘b‘:
b.send()