vars()
例
class foo:
def __init__(self, val_1, val_2):
self.val1 = val_1
self.val2 = val_2
afoo = foo(10, 20)
print(vars(afoo))
>>>
{'val1': 10, 'val2': 20}
Python tips
class foo:
def __init__(self, val_1, val_2):
self.val1 = val_1
self.val2 = val_2
afoo = foo(10, 20)
print(vars(afoo))
>>>
{'val1': 10, 'val2': 20}