Suppose you have the following object:
class Tarou:
def __init__(self):
self.name = 'tarou'
self.age = 15
tarou = Tarou()
tarou.height = 170
tarou.weight = 58
I remembered the comment from @shiracamus. There was a function that returned in dict format.
print(vars(tarou))
Execution result
{'name': 'tarou', 'age': 15, 'height': 170, 'weight': 58}
print(tarou.__dict__)
Execution result
{'name': 'tarou', 'age': 15, 'height': 170, 'weight': 58}
** If it is not the dict attribute, an error will occur. ** **
TypeError: vars() argument must have __dict__ attribute
#Key
tarou.__dict__.keys()
#value
tarou.__dict__.values()
Recommended Posts