type的原型,type(name, bases, dict) -> a new type ,生成一个新类,name是字符串即类名, bases 继承的类(为空时,继承type), dict是类的属性。python
<!-- lang: python --> def main(self): print 'hello world' s_dict = { "name": "Hello", "attr": {"a": 2}, "method": {"main": main} } if __name__ == '__main__': Hello = type(s_dict["name"], (), s_dict["method"]) hello = Hello() hello.main()