# Author: James Tam # Version: June 8, 2017 # Replaced sys.stdout.write() with print() # Version: November 17, 2011 (Python 3.X port) # A program by James Tam that reads in letter grades from a file # and displays the grades onscreen. inputFileOK = False while (inputFileOK == False): # Open file for reading, confirm file with user. try: # Get information about the file name at run time from the user. inputFileName = input("Enter name of input file: ") inputFile = open(inputFileName, "r") # Update user on what is happening. print("Opening file" + inputFileName, " for reading.") inputFileOK = True # While we haven't read past the end of the file continue reading from # it. for line in inputFile: print(line, end="") print("Completed reading of file", inputFileName) inputFile.close() print("Closed file", inputFileName) except IOError: print("Error: File", inputFileName, "could not be opened") else: print("Successfully read information from file", inputFileName) finally: print("Finished file input and output\n")