# L-28 MCS 260 Wed 31 Oct 2007 : readfilename2.py # # Prompts the user for a file name and displays # an error message if the name given by the user # does not correspond to a file. Asks to retry. while True: name = raw_input('Give the name of a file : ') try: file = open(name,'r') print 'opened ' + name + ' for reading' file.close() break except IOError: print 'file ' + name + ' does not exist?' retry = raw_input('Try again ? (y/n) ') if retry != 'y': break