面向对象(metaclass继承高级用法)


方法一:
# class MyType(type):

# def __init__(self,*args,**kwargs):
# print('132')
# super(MyType,self).__init__(*args,**kwargs)
# ###执行父类的init方法
#
#
# class Base(object,metaclass = MyType):####metaclass继承父类的
# pass







方法二:
# class Mytype(type):
# def __init__(self,*args,**kwargs):
# print('23')
# super(Mytype,self).__init__(*args,**kwargs)
# Base=Mytype('Base',(object,),{})



# class MyType1(type):
# def __init__(self,*args,**kwargs):
# print('sdsd')
# super(MyType1,self).__init__(*args,**kwargs)
#
# def with_args(arg):
# base=MyType1('Base',(arg,),{})
# return base
#
# class FOO(with_args(object)):
# pass
#
# FOO()









方法三:
class FOO1(type):
def __init__(self,*args,**kwargs):
print('223')
super(FOO1,self).__init__(*args,**kwargs)
class FOO2(metaclass=FOO1):
pass
FOO2()


posted @ 2018-11-21 14:18  风不再来  阅读(473)  评论(0编辑  收藏  举报