# Author: James Tam # Version: March 23 2010 # A program by James Tam that reads in letter grades from a file # and displays the grades onscreen. # Get information about the file name at run time from the user. inputFileName = raw_input ("Enter name of input file: ") inputFileOK = False while (inputFileOK == False): # Open file for reading, confirm file with user. try: inputFile = open (inputFileName, "r") inputFileOK = True except IOError: inputFileOK = False print "File", inputFileName, "could not be opened" else: # Update user on what is happening. print "Opening file", inputFileName, " for reading." # While we haven't read past the end of the file continue reading from # it. for line in inputFile: print line, print "Completed reading of file", inputFileName, finally: # Finished writing to file, provide feedback to user and close file. inputFile.close() print "Closed file", inputFileName