Hey guys! This is my very first post on this website.
Anyways, I just started learning Python, and am reading an ebook, called "A Byte Of Python".
So at the end, it says to create an address book application.
In my application, it basically just creates a text file with all the stored info.
What you can do is: browse contacts, add contacts, search for contacts.
Now, I need help on: deleting contacts, modifying contact information.
Could anyone please just help me with what code I would need to use to define a class to delete a specific line from the text file, and also to modify a specific line in the text file? For the modification though, I would prefer if you could help me in creating a class which only modifies the part of the line which the user requests (only mod phone number, email, etc.)
By class I do mean code like:
def class_here(): stuff here etc.
I have tried pretty much everything for modifying and deleting. For modifying, I have almost gotten the code, except that it does not actually change any information. It just implies that it worked. I had the code, but undid it in frustration and now I do not feel like writing it up again. It did not work anyways.
And as for deleting, I would like if the code could just delete a line specified by the user (e.g. enter name to delete: random name here -- delete the whole line of info).
I would appreciate if anyone could just give me the code and knowledge to start. It's not like I am asking to do the whole thing for me.
The code I have so far is:
# Filename: addressbook.py # Author: Aman Dureja temp1 = open("addressbookdata.txt", "a") def collect_info(): print("Okay, so this is where you input information about the contact! Let's start!") lastname = input("What is the contact's last name? ") firstname = input("What is the contact's first name? ") address = input("Where does the contact live? ") phone = input("What is the contact's phone number? ") email = input("What is the contact's email address? ") print("Alright, so in a list, what we have is: ") contact = [lastname, firstname,\ address,\ phone,\ email] print(contact) temp1 = open("addressbookdata.txt", "a") temp1.write(firstname + ' ' + lastname + ', ' + address + ', ' + phone + ', ' + email) temp1.write("\n") def search_people(): print("Alright, so here is where you would search for people already in the address book.") criteria = input("Please enter any keywords, including address, phone number, etc. for the search: ") temp1 = open("addressbookdata.txt", "r") for line in temp1: if criteria in line: print(line) else: print("Did not find person. Please add him/her/it to the address book first.") def browse_contacts(): print("Alright, so this is where you will see a list of all your contacts, and all their information.") temp1 = open("addressbookdata.txt", "r") readfile = temp1.read() print (readfile)
So yeah, long post but sums stuff up. All I need is for someone to help with the delete and modify classes.