class F: def __init__(self, name, age): self.name = name self.age = age
obj = F(‘tom‘, 20)s = obj.__dict__print(s) # {‘name‘: ‘tom‘, ‘age‘: 20}__dict__获取类中的属性,并以键值对的形式存储
python 中 __dict__函数的使用
原文:https://www.cnblogs.com/jinbaobao/p/12056410.html