This module is part of a simple todo app I made with Python...
def deleteitem():
showlist()
get_item = int(raw_input( "\n Enter number of item to delete: \n"))
f = open('todo.txt')
lines = f.readlines()
f.close()
lines[get_item] = ""
f = open('todo.txt','w')
f.writelines(lines)
f.close()
showlist()
The number of lines in f obviously changes as items are added to the list... Problem here is that for example if a user enters '10' when there are only 9 lines in the file ( or anything else not in range) , it exits as expected with :
IndexError: list assignment index out of range
What can I add to the module so as to have it prompt user to enter an item within the range? I am assuming maybe a Try block ... Or is there a way to catch an exception.. I am guessing there is an easy way to do this...