pathlib · with · json — Python file I/O done right | L08 · Advanced

Опубликовано: 16 Июнь 2026
на канале: Dargslan
51
1

File I/O is where every Python script meets the real world. Wrong path on Windows? Crash. Forgot to close a file? Silent corruption. Bad JSON? Cryptic error.

You'll learn:
• pathlib.Path — the modern path API (replaces os.path strings)
• Context managers (with) — auto-close, no leaks, even on errors
• json.load + json.dump — config files, API responses, data export
• CSV with stdlib — DictReader / DictWriter for tabular data
• Binary mode ("rb" / "wb") for non-text files
• The encoding=`"utf-8"` rule that prevents 80% of cross-platform bugs

The senior 1-liner:
`config = json.loads(Path("config.json").read_text(encoding="utf-8"))`

→ Files + JSON cheat sheet: https://dargslan.com
→ Next: L09 Modules + Packages — scripts → real codebases

#Python #pathlib #PythonJSON #FileIO #PythonAdvanced