I'm creating a program that carrys out certain things dependent on the user input. One function is to read text from a text file, another is to add text to the same text file. I'm unsure about how to add an exception handler to make sure the text input is in the right format,
The text file contains a list of people with their birthdays in the form
and I don't know what I would put around my code to add text, in order to not crash the program when text isn't entered in this format.
Any help is much appreciated.
print "You chose to add a new birthday" file = open("birthdays.txt", "r") filedata = file.read() newLine = raw_input("Enter the name and birthday: ") file = open("birthdays.txt", "a") file.seek(0) file.write(newLine + "\n") file.close()