← TOC

Chapter 6: Files & Paths

pathlib

from pathlib import Path

root = Path(__file__).resolve().parent
cfg = root / "config" / "app.json"

JSON

import json
from pathlib import Path

Path("data.json").write_text(json.dumps({"a": 1}, indent=2), encoding="utf-8")

Loading comments...