9.3. File Built-in Methods

Once open() has completed successfully and returned a file object, all subsequent access to the file transpires with that “handle.” File methods come in four different categories: input, output, movement within a file, which we will call “intra-file motion,” and miscellaneous. A summary of all file methods can be found in Table 9.3. We will now go over each category.

9.3.1. Input

The read() method is used to read bytes directly into a string, reading at most the number of bytes indicated. If no size is given, the default value is set to -1, meaning that the file is read to the end. The readline() method reads one line of the open file (reads all bytes until a NEWLINE character is encountered). The NEWLINE character ...

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.