__dict__

  • 以字典形式返回对象中封装的内容
class C:

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

obj = C('python')
print(obj.__dict__)
print(C.__dict__)

输出结果:

  {'name': 'python'}

  {'__module__': '__main__', '__init__': <function C.__init__ at 0x00000000022999D8>, '__dict__': <attribute '__dict__' of 'C' objects>, '__weakref__': <attribute '__weakref__' of 'C' objects>, '__doc__': None}

原文地址:https://www.cnblogs.com/dongmengze/p/9512093.html