Challenge 1
Build the path project/src/main.py.
from pathlib import Path
source =
print(source)
Press Ctrl⌘Enter to check your answer
Practice composing, searching, comparing, normalizing, expanding, splitting, and converting filesystem paths with pathlib and selected os.path functions, including drive/root/tail decomposition, path identity, environment-variable expansion, and str/bytes interoperability.
Challenge 1
from pathlib import Path
source =
print(source)
Press Ctrl⌘Enter to check your answer
Challenge 2
from pathlib import Path
path = Path('reports') / 'summary.csv'
suffix =
print(suffix)
Press Ctrl⌘Enter to check your answer
Challenge 3
from pathlib import Path
source = Path('reports') / 'summary.csv'
json_path =
print(json_path)
Press Ctrl⌘Enter to check your answer
Challenge 4
from pathlib import Path
from tempfile import TemporaryDirectory
with TemporaryDirectory() as folder:
report = Path(folder) / 'report.txt'
report.touch()
result =
print(result)
Press Ctrl⌘Enter to check your answer
Challenge 5
from pathlib import Path
from tempfile import TemporaryDirectory
with TemporaryDirectory() as temporary:
root = Path(temporary)
(root / "archive").mkdir()
(root / "notes.txt").touch()
(root / "archive" / "nested.txt").touch()
entries = sorted(root.(), key=lambda path: path.name)
print([entry.name for entry in entries])
Press Ctrl⌘Enter to check your answer
Challenge 6
from pathlib import Path
from tempfile import TemporaryDirectory
with TemporaryDirectory() as temporary:
root = Path(temporary)
(root / "nested").mkdir()
(root / "root.csv").touch()
(root / "nested" / "inside.csv").touch()
csv_files = sorted(
path.relative_to(root).as_posix()
for path in root.("*.csv")
)
print(csv_files)
Press Ctrl⌘Enter to check your answer
Challenge 7
import os
paths = [
os.path.join("workspace", "reports", "current.csv"),
os.path.join("workspace", "reports-old", "archive.csv"),
]
shared =
print(shared)
Press Ctrl⌘Enter to check your answer
Challenge 8
from pathlib import Path
requested = Path("~/reports/today.csv")
expanded =
print(expanded.is_absolute())
print(expanded.name)
Press Ctrl⌘Enter to check your answer
Challenge 9
from pathlib import Path
candidate = Path.cwd() / "folder" / ".." / "report.txt"
resolved =
print(".." in resolved.parts)
Press Ctrl⌘Enter to check your answer
Challenge 10
from pathlib import Path
import os
base = Path.cwd() / "project"
target = base.parent / "shared" / "data.csv"
relative =
print(Path(relative).parts[0] == "..")
Press Ctrl⌘Enter to check your answer
Challenge 11
import os
from pathlib import Path
from tempfile import TemporaryDirectory
with TemporaryDirectory() as temporary:
root = Path(temporary)
(root / "nested").mkdir()
report = root / "report.txt"
report.write_text("data", encoding="utf-8")
alternate = os.path.join(str(root), "nested", "..", "report.txt")
same =
print(same)
Press Ctrl⌘Enter to check your answer
Challenge 12
import os
raw = os.path.join("reports", "2026", "..", "summary.csv")
normalized =
print(normalized == os.path.join("reports", "summary.csv"))
Press Ctrl⌘Enter to check your answer
Challenge 13
import os
from pathlib import Path
from tempfile import TemporaryDirectory
with TemporaryDirectory() as temporary:
path = Path(temporary) / "report.txt"
path.touch()
encoded = os.fsencode(path)
restored =
print(restored == str(path))
print(type(encoded).__name__)
Press Ctrl⌘Enter to check your answer
Challenge 14
import os
from unittest.mock import patch
with patch.dict(os.environ, {"FOXIPA_REPORTS_ROOT": "workspace/reports"}, clear=True):
requested = "$FOXIPA_REPORTS_ROOT/summary.csv"
expanded =
print(expanded)
Press Ctrl⌘Enter to check your answer
Challenge 15
import ntpath
path = r"\\server\share\logs\app.log"
drive, root, tail =
print(repr(drive))
print(repr(root))
print(repr(tail))
print(drive + root + tail == path)
Press Ctrl⌘Enter to check your answer