Ok so I'm working on an address book app in python. the user writes contacts into a txt file and can search for it and everything.(run the code yourself if you want to see what it does)
now for my problem,
under "#if editing"
i want have the user search for a contact and delete that line. but i have no clue how to use remove(x), or pop(x) when working with files. Thanks
Below is my code
#what to do
print ""
action=raw_input("Are you [1]Creating/Editing entrys or [2]Searching for an existing entry? ")
# IF Creating or editing
if action=='1':
action2=raw_input("Would you like to create a [1]new entry or [2]edit an existing one? ")
#if creating new
if action2=='1':
fob=open('/Users/NSutton/Simple Adress/bookdata.txt','w')
fname=raw_input("First Name: ")
lname=raw_input("Last Name: ")
pnum=raw_input("Phone: ")
email=raw_input("Email: ")
address=raw_input("Adress: ")
fob.write(fname + " " + lname + ", " + pnum + ", " + email + ", " + address)
fob.write("\n")
fob.close()
#if editing
if action2=='2':
fob=open('/Users/NSutton/Simple Adress/bookdata.txt','r')
searchcriteria=raw_input("Enter the name of the contact you'd like to delete: ")
for line in fob:
if searchcriteria in line:
print line
#confirm this is the contact you want to delete
confirmdel=raw_input("Is That the contact you wish to delete? [yes or no]")
if confirmdel=="yes":
#IF searching
if action=='2':
fob=open('/Users/NSutton/Simple Adress/bookdata.txt','r')
searchcriteria=raw_input("Enter your search criteria (name,phone ect.): ")
for line in fob:
if searchcriteria in line:
print line
#If no data matches search
else:
print "Error: No contact matching search."