I don't understand how to get the value of a field instance from python class. I added what I need this code to do in get_person method. The output should be 3 or None.
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())
Digitdefined?'Team=Hawkeye|Weapon=Bow|Person=3'when you know you will need to access these values is a poor design. Consider passing in a dictionary instead, then the problem goes away. Or parse those values out in the__init__()method so they are available. Also having a single property likedigitthat represents more than one kind of thing — sometimes a string like"Comics"sometimes key/value pairs — is a bad idea. What is it supposed to represent?