我不明白如何从 python 类中获取字段实例的值。我在 get_person 方法中添加了我需要此代码执行的操作。输出应为 3 或无。
class Digit:
def __init__(self, digit)
self.digit = digit
def get_person(self):
# I want to get the value for the field 'Person' from digit, if 'Person' exists
# else None
inst1 = Digit('Team=Hawkeye|Weapon=Bow|Person=3')
inst2 = Digit('Comics')
print(inst1.get_person(),
inst2.get_person())