What file modes exist, and why always pass `encoding`?
BeginnerConceptExceptions, context managers, files & logging
Answer
Modes: r read, w truncate and write, a append, x create and fail if exists, + read/write, b binary. Text mode decodes bytes using encoding; if you omit it, Python uses the locale encoding, which is UTF-8 on most Linux boxes but can be ascii in a minimal container (LANG unset) or cp1252 on Windows. That produces UnicodeDecodeError only in production. Always pass encoding="utf-8" (3.15 makes UTF-8 the default; PYTHONWARNDEFAULTENCODING=1 flags the omissions today).
More on Exceptions, context managers, files & logging
How does `try` / `except` / `else` / `finally` work?BeginnerWhy is a bare `except:` (or `except Exception: pass`) dangerous?BeginnerWhat is exception chaining, and what is `raise ... from`?IntermediateWhen should you define custom exception classes?IntermediateWhat is the EAFP vs LBYL style, and which does Python prefer?IntermediateHow does a `with` statement work, and why use it for files?Beginner