元类例子

class AAA(type):
def __init__(self,name,father,data):
print('haha')
super(AAA, self).__init__(name,father,data)

def __call__(self, *args, **kwargs):
print('------==')
cc = object.__new__(self)
self.__init__(cc, *args, **kwargs)
print('++')
return cc



class MySQL(object,metaclass=AAA):
def __init__(self,host,port):
self.host=host
self.port=port
print('fdsf')

# @classmethod
# def from_conf(cls):
# print(cls)
# return cls(settings.HOST,settings.PORT)

def __call__(self, *args, **kwargs):
print('-aaa-----==')

print('aaaa')

MySQL('111',33)

猜你喜欢

转载自www.cnblogs.com/xulian/p/10157348.html