马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
目的: 自由选择继承的父类是哪个.
方法: 使用type()函数.
type can be used to dynamically create a class. First parameter is the class name, second are the classes to inherit from and third are the initial attributes.
示例:
class ParentA:
def a(self):
print('hi, A')
class ParentB:
def b(self):
print('hi, B')
obj = type(
'Child_class', # class name
(ParentA, ParentB), # parent classes
{
'info': lambda self: print('hi, child')
}
)()
obj.a()
obj.b()
obj.info()
https://stackoverflow.com/questi ... lass-using-argument |