Reading Files

To read data from a file use the .read() method to read the whole file.

fileContent = fileName.read( )

Use the .readline() method to read a line at a time.

nextLine = fileName.readline( )

When opening a file for writing use either

  • “r” opens a file for reading, error if the file does not exist
  • “r+” opens a file for both reading and writing
video