I am continuing on a program that I had written earlier, and am trying to save the data inputted in a separate file, so when I reopen the program, I keep the data.
addressbook = []
class Parent:
def Create(self):
create_contact = input('''Please input the details of the contact you would like to create.
''')
addressbook.append(create_contact)
print("Successfully added")
return
def Remove_contact(self):
remove_contact = input('''Please input the details of the contact you would like to remove.
''')
if remove_contact in addressbook:
print(addressbook.remove(remove_contact))
print("Successfully removed contact.")
else:
print("Error", search_contact, "not found in the list")
return
def Search(self):
search_contact = input('''Please input the details of the contact you would like to search for.
''')
if search_contact in addressbook:
print(search_contact, "found in Address Book")
else:
print("Error", search_contact, "not found in the list")
return
def Display_contacts(self):
print("Displaying contacts....", addressbook)
return
def menu(parent):
menu = input('''Address book to store friends contact
-------------------------------------------------------------
-------------------------------------------------------------
Select an option...
1 - Add/Update contact...
2 - Display all contacts...
3 - Search...
4 - Delete contact...
5 - Quit
''')
if menu == '1':
parent.Create()
elif menu == '2':
parent.Display_contacts()
elif menu == '3':
parent.Search()
elif menu == '4':
parent.Remove_contact()
elif menu == '5':
print("Quitting program")
quit()
else:
print("I did not understand that... Please try again")
p = Parent()
menu(p)
This is my old code, and am thinking about importing a file which contains a list, and adding to that list. Is that an appropriate method or is there and easier way? Thank you!
quit()