Python 元类应用,动态创建类,动态继承
class Person:
def __init__(self, name, age):
print(name, age)
self.name = name
self.age = age
def __init__(self, sex, name, age):
super(Student,self).__init__(name,age)
self.sex = sex
print(self.sex)
class B:
def __init__(self, a):
self.B = "B"
super(Student, self).__init__(1, 2)
def run(self):
print(self.name)
Student = type('Student', (Person,), {'__init__': B.__init__, "run":B.run})
s1 = Student("a")
s1.run()