#Author: James Tam #Version: October 28, 2024 #Learning objective: #*Opening a file. #*Reading a single line from a file. #*Reading multiple lines from a file until the end. #*Closing a file #Limitation: #*Assumes the file is the same location as this python program. #*Asumes no problems opening/reading from the file file_name = input("Type in the complete file name including extension (e.g. input.txt): ") #r = open file for reading aFile = open(file_name,"r") #aFile: a file variable that connects program with file. #Actions on the file variable will be made on the actual file. aLine = aFile.readline() print(aLine) #Breaks the connection between the file variable and program. #*File is now accessible by other programs. #*Anything buffered (stored by program) is now written to the file (if file output occurs in the program). aFile.close() print("-") #Reads line by line from file from beginning to end. aFile = open(file_name,"r") for line in aFile: #readline returns the information in the form of a string print(line) aFile.close()