pathlib (Modern Path Handling)
PY · File I/Ofrom pathlib import Pathfrom pathlib import Path
data_dir = Path("project") / "data"
data_dir.mkdir(parents=True, exist_ok=True)
config = data_dir / "settings.json"
config.write_text('{"debug": true}', encoding="utf-8")
print(config.read_text())
print(config.suffix, config.stem){"debug": true}
.json settingsNote pathlib is the modern replacement for os.path. The / operator joins paths. Use .resolve() for absolute paths, .exists() to check existence.