File Handling

End of File Handling (3 marks)

Consider the following code used to read a file until the end: myFileHandler = open(“myFile.txt”) while NOT myFileHandler.endOfFile() print(myFileHandler.readLine()) endwhile myFileHandler.close() (a) Explain what the endOfFile() method does in this context. (1 mark) (b) What does readLine() do in this loop? (1 mark) (c) Why is it important to close the file after all operations […]

End of File Handling (3 marks) Read More »

File Handling 2

Study the code below and explain what it does, line by line. 001 newFile = open(“file.txt”) 002 while NOT newFile.endOfFile() 003         print(newFile.readLine()) 004 endwhile 005 newFile.close()

File Handling 2 Read More »

Shopping Cart