Study
Python · Files: reading and writing
Opening files with with-blocks, text vs binary modes, encodings, reading line by line, and pathlib.
- The with statement closes the file even if an exception happens.
- Always pass encoding="utf-8" for text files; the default depends on the operating system.