__dict__ 是类的内置属性,用于以字典的形式存储类里的属性,也就是存储那些 self.xxx 的属性
[root@localhost ~]$ cat 1.py #!/usr/bin/env python #-*- coding:utf-8 -*- class People(object): def __init__(self): self.name = 'Tom' self.age = 23 obj = People() print obj.__dict__
[root@localhost ~]$ python 1.py {'age': 23, 'name': 'Tom'}