SOARDO
Software Engineer (SDE)pythonbeginner3 interactive MCQs in app

os & pathlib Modules

Path / cross-platform joining & mkdir(parents=True, exist_ok=True)path traversal prevention via .resolve() + is_relative_to()Path("/a") / "/b" root overwrite pitfall

Use `pathlib.Path` over fragile string concatenation (`folder + "/" + file`): `/` operator (`Path("data") / "2026" / "out.csv"`) normalizes separators cleanly across Windows (`\`) and Linux (`/`), while `.stem`, `.suffix`, `.parent`, `.resolve()`, `.mkdir(parents=True, exist_ok=True)`, and `.read_text(encoding="utf-8")` replace nested `os.path` calls cleanly!

`out = Path("reports") / f"{slug}.csv"; out.parent.mkdir(parents=True, exist_ok=True)` builds cross-platform nested folders in two lines cleanly!
(SECURITY CRITICAL!) joining untrusted filenames (`"../../etc/passwd"`) with `base / filename` jumps OUTSIDE `base` cleanly (`Path("/uploads") / "/etc/passwd"` evaluates straight to `"/etc/passwd"`!). Always validate `target = (base / name).resolve(); target.is_relative_to(base.resolve())`!
Python pathlib — Real Pythonread ↗os & pathlib Modules — Applied Practicepractice ↗Exercism Python Track (Interactive)practice ↗

Practice os & pathlib Modules with 3 graded MCQs & written feedback.

Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.

Test yourself free on SOARDO →View full Software Engineer roadmap

More Software Engineer Study Guides