类的创建时是用type 实现的 

def __init__(self, name):
    self.name = name 

def fun(self):
     print("%s is talking'%self.name)


func = type('foo', (object, ), { 'talk':fun, '__init__', __init__)

f = func('alex')
f.talk()

  

 

posted on 2018-05-28 21:16  python我的最爱  阅读(176)  评论(0编辑  收藏  举报