#-*-coding:utf-8-*-
#__author:martin
#date:2017/10/18
class MyType(type):
def __init__(self,*args,**kwargs):
print("遇到类名....")
def __call__(self, *args, **kwargs):
print('类名加() ....')
ret = self.__new__(Foo)
self.__init__(self)
return ret
class Foo(object,metaclass=MyType):
def __new__(cls, *args, **kwargs):
print('生成对象....')
return 'python'
def __init__(self):
print('执行构造方法...')
obj = Foo()
print(obj)
执行结果:
遇到类名….
类名加() ….
生成对象….
执行构造方法…
python