我已经做了一个联系人管理器,我有:
def look_up_contact():
print("-------------------------------------------------")
choice = input("Please enter the last name of the contact you would like to view: ")
print("-------------------------------------------------")
person_list = Contacts[choice]
try:
for person in person_list:
print("Contact: " + person.get_last_name() + ", " + person.get_first_name())
print("Phone Number: " + person.get_phone_num())
if type(person) == Friend:
print("Email: " + person.get_email())
print("Birthday: " + person.get_birth_date())
我如何修改它以查看文本文件?
我了解基础知识,但这很棘手
textcontacts = open( 'contacts.txt' )
如果在 'person' 或 txt 中找不到人员,我还想提供一些关于添加错误消息的反馈:
我尝试过尝试:方法
except Exception as ex:
print(' Sorry, The person you are looking for could not be found ')
我正在使用 python 3.x