Edit a line in a file depending on user’s input | Python

I’m working on a contact book application to improve my python skill, so far I’ve created functions to add new contact, view existing contact, but I’m stuck on a function to edit them, I don’t know how to tackle this task (note that editing and adding information is based on user input), currently the only information this application is recording are name, phone number and/or email (if user entered an email).

Getting user input

I am running this: import csv import sys reader = csv.reader(open(sys.argv[0], "rb")) for row in reader: print row And I get this in response: ['import csv'] ['import sys'] ['reader = csv.reader(open(sys.argv[0]', ' "rb"))'] ['for row in reader:'] [' print row'] >>> For the sys.argv[0] I would like it to prompt me to enter a filename. … Read more

Limiting Python input strings to certain characters and lengths

I just started learning my first real programming language, Python. I’d like to know how to constrain user input in a raw_input to certain characters and to a certain length. For example, I’d like to show an error message if the user inputs a string that contains anything except the letters a-z, and I’d like to show one of the user inputs more than 15 characters.