Reading and Writing Text Files
open() gives you a file object, with reads a file object safely, and four methods cover every text file you will ever process.
Reading and writing text and binary files, file modes, context managers, positions and paths.
4 notes
open() gives you a file object, with reads a file object safely, and four methods cover every text file you will ever process.
The mode string decides whether a file is read, written, appended or created, and whether it is treated as text or bytes. The with statement makes any...
Binary mode gives you the raw bytes, and seek and tell let you move around inside a file instead of reading it from start to finish.
pathlib turns file paths into objects with methods. It replaces string joining and most of os.path, and it works the same on Windows, macOS and Linux.