I'm trying to delete from a file.
This is what I am trying to do.
1.importing Easygui
2.Put three modes plus quitting
- 3 modes are (see, add, delete)
Everything is working except deleting part. this is what I have
import easygui
filea = open('GroceryList.txt', 'a')
fr = open('GroceryList.txt', 'r')
filer = open('GroceryList.txt', 'r')
runinng = True
while runinng:
a = easygui.choicebox('Do you want to add, delete, or see your list?',
choices = ['add', 'delete', 'see', 'quit'])
if a == 'add':
ad = easygui.enterbox('What do you want to add')
filea.write(ad)
filea.write('\n')
filea.close()
filea = open('GroceryList.txt', 'a')
elif a == 'delete':
rn = easygui.enterbox('What are you going to delete?')
rl = fr.readlines()
for lines in fr:
if rn in lines:
line.split()
fr.close()
fr = open('GroceryList.txt', 'r')
elif a == 'see':
s = filer.readlines()
easygui.msgbox(s)
filer.close()
filer = open('GroceryList.txt', 'r')
elif a == 'quit':
runinng = False
filea.close()
fr.close()
filer.close()
The part that is not working is:
elif a == 'delete':
rn = easygui.enterbox('What are you going to delete?')
rl = fr.readlines()
if rn in fr:
line.remove()
fr.close()
fr = open('GroceryList.txt', 'r')