在类内调用__dict__,会返回类内所有变量和函数的dict。
例
class Python:
a = 1
b = 5.1
def _init(self):
return 100
def wdx(self):
return Python.__dict__.items()
py = Python()
dic = py.wdx()
print(dic)
==========结果=========
dict_items([('__module__', '__main__'), ('a', 1), ('b', 5.1), ('_init', <function Python._init at 0x0000021A21A0D598>), ('wdx', <function Python.wdx at 0x0000021A38B3B268>), ('__dict__', <attribute '__dict__' of 'Python' objects>), ('__weakref__', <attribute '__weakref__' of 'Python' objects>), ('__doc__', None)])