Sahaj.blogs

Day page

29 Sept 2023

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.

Read the post →