When I run the code as below, it returns attribute error.
AttributeError: 'Contact' object has no attribute 'find_info'
How should I fix this??
phonebook = {}
Contact = namedtuple('Contact', ['phone', 'email', 'address'])
def add_contact(phonebook):
name = input()
phone = input()
email = input()
address = input()
phonebook[name] = Contact(phone, email, address)
print('Contact {} with phone {}, email {}, and address {} has been added successfully!' .format(name, phonebook[name].phone, phonebook[name].email, phonebook[name].address))
num = 0
for i in phonebook.keys():
if i in phonebook.keys():
num += 1
print('You now have', num, 'contact(s) in your phonebook.')
def consult_contact(phonebook):
find_name = input('What is the name of the contact?\n')
find_info = input('What information do you need?\n')
if find_name not in phonebook:
print('Contact not found!')
else:
print(phonebook[find_name].find_info)
if __name__ == "__main__":
add_contact(phonebook)
consult_contact(phonebook)
print(phonebook[find_name].find_info)- the error message would have included relevant line. If such a line (the only usage offind_infoas a property as well) is presumed to be valid, remove all non-related code and provide a minimal example case. If the question is about "How can I access a NamedTuple property from a string?", again, remove all non-related code and focus on the specific issue.namedtupleitself would have resulted in an error.