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()

posted @ 2023-04-24 15:31  道友请留步W  阅读(54)  评论(0编辑  收藏  举报