Skip to main content
PRACTICE / APPLIED PYTHON / LESSON 03

Filesystem & Data Pipelines Coding Clinic.

Eight original Python challenges: safe pathname resolution, real UTF-8 file reads, CSV structures, duplicate rows, JSON validation, deterministic serialization, staged output and a complete fictional inventory analyzer.

8 coding challengesReal Python file operationsAdditional test casesIsolated filesystem

Where files go: These exercises use real Python pathlib, tempfile, csv and json in a browser-isolated virtual filesystem, not your Windows or macOS files. Changes are intentionally temporary and never access customer systems. Run allows experimentation; Check evaluates the stated example and additional cases.

For an end-to-end local exercise, return to the guarded CSV-to-JSON project after completing the clinic.

JOELEARNS / PYTHON WORKBENCH

Write it. Run it. Understand it.

Work with pathlib, real temporary Python files, CSV/JSON schema validation and staged reports inside the isolated browser filesystem.

Python 3.14 · in-browser
CHALLENGE 01 / 8 · INTERMEDIATE

Resolve a file inside an approved folder

Write safe_file(root, filename) using pathlib.Path. Return a resolved Path only when filename is a relative file path inside root, has no '..' path component, isn't the root directory itself, and resolves inside the root. Otherwise return None. For root '/northstar/incoming' and 'inventory.csv', print the complete resolved path. The grader changes folder names and tries traversal, absolute and sibling-prefix paths. Don't create or delete any files.

EXPECTED OUTPUT/northstar/incoming/inventory.csv
script.py editableCtrl / Cmd + Enter to run
Your code is stored only in session storage when enabled. Never paste secrets. Clearing this option clears saved drafts, not the editor.
Code executes only when you choose Run or Check. No account needed.
HINTS · OPTIONAL

Try solving it before asking for help. Hints never show a completed program.

PYTHON OUTPUTReady

Your printed output and errors will appear here.

VARIABLE TRACER

Run the code, then step through the executed lines to watch variable values change.

About this environment: The Python runtime is loaded on demand from a version-pinned CDN and runs inside a sandboxed, opaque-origin browser frame. Runs have a time limit. OS/network automation is outside this introductory workbench. If your code calls input(), a response panel appears to supply text to those calls. Don't paste secrets or untrusted scripts.