Skip to content
Learn Netverks

Lesson

Step 26/36 72% through track

pathlib-os

pathlib and os

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches pathlib and os: the syntax, patterns, and safety habits you need before advancing in Python.

Teams still ship pathlib and os in Python codebases—skipping it leaves gaps in debugging and code reviews.

You will apply pathlib and os in contexts like: ETL scripts, log ingestion, and config-driven automation.

Write Python 3 in the editor and click Run on server—the dev runner executes your script with print() for output; stdlib only in playground snippets (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

pathlib.Path offers object-oriented paths—prefer it over string concatenation for cross-platform code. The os module provides lower-level process and filesystem utilities.

pathlib basics

from pathlib import Path

root = Path(".")
for py_file in root.glob("*.py"):
    print(py_file.name)
joined = Path("data") / "logs" / "app.log"

os module snippets

import os
print(os.getcwd())
print(os.environ.get("HOME", "unknown"))

In the playground, path globs may be limited—practice full directory walks locally.

Important interview questions and answers

  1. Q: Path vs os.path?
    A: pathlib is higher-level and composable with /; os.path is legacy string-based but still common in older code.
  2. Q: Absolute vs resolve()?
    A: resolve() makes absolute and resolves symlinks where possible.

Self-check

  1. How join path parts with pathlib?
  2. What does Path.glob do?

Tip: Prefer Path over string paths—Path("data") / "file.txt" is cross-platform.

Interview prep

Path vs os.path?

pathlib object-oriented and composable; os.path string-based legacy API.

Path.glob?

Yield paths matching pattern—like shell glob in Python.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Path vs os.path?
  • glob when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump