Course · Beginner · 5 h · Available in Spanish, English:
Practical Python: files and debugging
Read and write CSV and JSON files with Python's standard library
Milestone by milestone, you'll build `ordena`: a command-line tool in Python that brings order to a chaotic downloads folder. In two minutes, the first lesson shows you how a naive script loses a file; from there you build the version that loses nothing. You scan the files, classify them by type and by month, detect duplicates by content, propose a move plan that never overwrites, and apply it only once you confirm, with an undo log that works even if the process is interrupted. Then you give it an argparse interface with correct exit codes, TOML configuration with flag > file > default priority, a pytest test suite, and a pyproject.toml with a README. You test every command by calling `main` with its arguments on test folders, and you finish with a challenge on a folder you've never seen. Everything happens on the course page, in about 7.5 hours. You need to know how to write functions, work with files and exceptions, and have written at least one test.
A sample lesson
from dataclasses import dataclass
from pathlib import Path
@dataclass(frozen=True)
class Movimiento:
origen: Path # where the file is today
destino: Path # where it will end up if the plan is applied
def describir(plan, raiz):
"""Devuelve líneas de texto; solo la CLI las imprime."""
return [f"{m.origen.relative_to(raiz)} -> "
f"{m.destino.relative_to(raiz)}" for m in plan]Available in: EN · ES
20 lessons and about 7 h 38 min of content. You go at your own pace, with no fixed dates.
By the end you will be able to: Design and build a CLI with argparse featuring subcommands, validated options, text or JSON output, and correct exit codes; Write pytest tests on temporary folders that fail when someone plants a bug in the tool; Turn expected errors into clear messages without tracebacks and protect destructive operations with simulation and undo.