# Author: James Tam # Version: June 7, 2017 # Replace sys.io etc. with print(,end="") # Version: October 17, 2014 # A modified version of the original 'grades1.py' program. # The functionality is identical but the way that this version reads from file # less "Python-like" and is closer to how file-input is implemented in many # programing languages. # Get information about the file name at run time from the user. # Try it with "gpa.txt" or "letters.txt" as the input file. inputFileName = input ("Enter name of input file: ") inputFile = open(inputFileName, "r") print("Opening file", inputFileName, " for reading.") # Line either refers to a string of text from the file # or an empty string if nothing can be read from the file. line = inputFile.readline() # While we haven't read past the end of the file continue reading from it. # When readLine can't read from file an empty string will be returned so # this is what's used to form the Boolean expression for the loop. while (line != ""): print(line, end="") line = inputFile.readline() inputFile.close() print("Completed reading of file", inputFileName)