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