# python一切皆对象
class Foo(object): def __init__(self, name, version=None): self.name = name self.version = version def __setstate__(self, state): self.name = state.get('name', 'LiShiChao') self.version = state.get('version', '0.0.1') def main(): obj = object.__new__(Foo) # 创建一个空对象 print(dir(Foo)) # 给init赋值 if hasattr(obj, '__setstate__'): obj.__setstate__({}) print(obj.version) if __name__ == '__main__': main()
标签:__,.__,name,self,object,version From: https://www.cnblogs.com/root0/p/16891657.html