Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🐍 David's Python Intermediate

From 100-line scripts to 400-line tested programs — the intermediate course that runs in your browser and grows into your terminal.

PyI course icon

Read a little. Trace a lot. Break things on purpose. Ship 3 tested programs.
Python 3.12 • 139 runnable code boxes • Built-in console • 6 quizzes • 21 exercises • 3 capstones

Python 3.12 Runs in browser No install Offline ready Private

Prerequisite: this course starts where David's Python Foundations ends. You should be comfortable with variables, loops, lists/dicts, functions, basic classes, files + try/except. Not sure? Lesson 0.2 is a 10-task entry diagnostic — score under 7/10 and it tells you exactly which Foundations modules to redo.


⚡ Quick start

Browser edition (recommended start — zero install)

An interactive intermediate Python course in a single HTML file.

  1. Open python-intermediate.html in any modern browser (Firefox, Chrome, Edge, Safari — Windows, macOS, Linux, Chromebook).

That's it. You get:

  • 139 runnable / editable code boxes (+ 29 reference boxes and transcripts)
  • Built-in Python console (REPL), sharing state with the lesson boxes
  • 6 quizzes (30 questions), 21 exercises with solutions, 3 portfolio capstones
  • Python runs locally in your browser tab and stays completely local
  • First load fetches the Python engine (~10 MB) once; after that it works offline
  • Progress and saved edits are stored by your browser (localStorage, separate pyi:* namespace — safe to run side-by-side with Foundations)

Desktop edition (for real files, CLIs, venv, pytest)

The exact same course, running in a native window on your system via Python 3 + PySide6 (Qt). Same lessons, boxes, console, quizzes, and progress — files persist in ~/.pyintermediate/workspace/.

  1. Install PySide6 (Python 3.9+ required):
pip install -r requirements.txt
# or simply:
pip install PySide6

Per-OS hints:

# Windows (python.org Python, tick "Add Python to PATH"):
py -m pip install PySide6

# macOS:
python3 -m pip install PySide6

# Ubuntu / Debian:
sudo apt install python3-pyside6   # or: pip install PySide6

# Fedora:
sudo dnf install python3-pyside6   # or: pip install PySide6

# Arch:
sudo pacman -S pyside6             # or: pip install PySide6
  1. Run it (keep py-intermediate.py in the same folder as python-intermediate.html):
python3 py-intermediate.py
# Windows alternative:
py py-intermediate.py

py-intermediate.py parses python-intermediate.html live at startup, so the two files must stay together. You can also pass an explicit path: python3 py-intermediate.py path/to/python-intermediate.html.


📁 Repository files

File Role
python-intermediate.html The whole course. Content + browser runtime in one self-contained file (favicon embedded). This is the only file you need for the browser edition.
py-intermediate.py Desktop edition. Parses python-intermediate.html and renders it with PySide6 — same lessons, code boxes, console, quizzes, progress. Runs on Windows 10/11, macOS 12+, and major Linux distros.
requirements.txt Desktop dependency (PySide6>=6.5). Install with pip install -r requirements.txt.
course-icon.svg Course icon (PyI badge). Used for the README and the desktop window icon.
README.md This file — the friendly guide.

Do not edit python-intermediate.html unless you mean to change the course itself — your edits and progress are stored separately by the app.


What is this?

David's Python Intermediate is a complete intermediate Python 3 course packed into a single file: python-intermediate.html.

It assumes ~100-line Foundations programs and graduates you to 200–400-line tested, CLI-driven programs built from the standard library plus pytest: comprehensions and generators, dataclasses and properties, pathlib/csv/json/sqlite3, argparse/logging/pytest, decorators and context managers — ending in three capstones (CLI tool, CSV→SQLite reporter, tested mini-API).

Open it, and you get a real Python interpreter, a code-review-minded textbook, a crash lab, a quiz master, and a terminal coach — all in one tab.

from collections import Counter

votes = ["yes", "no", "yes", "yes"]
print(Counter(votes).most_common(1))  # [('yes', 3)] — Module 1 in one line
# 👆 That box is live in the course. Predict. Trace. Run. Break it.

⚡ Try it in 30 seconds

  1. Double-click python-intermediate.html — or drag it into Firefox, Chrome, Edge, or Safari.
  2. Wait once for the Python engine to wake up (~10 MB download, first load only).
  3. In Lesson 0.1, predict what the Counter box prints, trace counts["berry"] on paper, then press ▶ Run.

That's the whole workflow of the course:

Read → Predict → Run → Tinker → Break → Fix → Build

…with the intermediate layer added between Predict and Run: Predict → Trace → Run ("what is x at line N?" before you touch Run).

Works on Windows, macOS, Linux, and Chromebook. The browser covers concepts; from Module 6 on you'll also use your terminal (venv, real files, pytest) — Lesson 0.3 sets it up in five minutes.


🟢🟡🔴 Where does each lesson run?

Every lesson wears one badge (legend also in Lesson 0.3):

Badge Meaning You…
🟢 Browser-safe Runs identically in this tab (Pyodide) press Run here
🟡 Browser-adapted Same concept, shimmed I/O (in-memory files / pyfetch) run here, read the banner, redo on your PC with real files / requests
🔴 Terminal-required Needs a real CLI: venv, multi-file, pytest do it on your PC — the browser box is read-only

Rule of thumb for the whole course: browser for concepts, terminal (or the desktop edition) for real files, CLIs, venv, and pytest.


💚 Why intermediates actually finish this one

Instead of... You get...
"You're past beginner, good luck" A 0.2 entry diagnostic that proves readiness (or prescribes exactly what to redo)
Endless syntax lists Idioms that delete code — comprehensions, unpacking, Counter, genexps, dataclasses
Toy snippets 3 portfolio capstones (CLI tool, data reporter, mini-API) with spec → build order → tests
Fear of real tooling venv, argparse, logging, pytest, pdb taught as transcripts + real runs, never faked
Silent bad habits 🐞 crash labs in every module — mutable defaults, late binding, exhausted generators, greedy regex, swallowed exceptions
Abstract quizzes elsewhere 6 in-page quizzes (30 questions) with instant explanations
Losing your place Auto-saved edits, progress bar, lesson checkmarks, dark/light theme — all stored locally

🗺️ What you'll learn — the full map

From Counter one-liners to a tested JSON API.

Module You'll learn You'll build
0 · Bridge In What "intermediate" means, entry diagnostic, browser↔terminal setup, traceback refresher venv + project folder, trace-table habit
1 · Pythonic Data Comprehensions (and when NOT), enumerate/zip/sorted(key), * unpacking, Counter/defaultdict/namedtuple, join, truthiness Top-words reporter
2 · Functions as Objects First-class functions, lambda discipline, closures + late-binding trap, map/filter vs comps, itertools, lru_cache/partial Dispatch table, ranked leaderboard
3 · Lazy Python Iterator protocol, yield, yield from, genexps, lazy pipelines, contextlib bridge Log pipeline, chunked batches
4 · OOP That Pays @dataclass, str/repr/eq/len, composition vs inheritance, @property validation, custom exceptions + raise from Refactored Bank account lab
5 · Files, Data & Storage pathlib, csv (quoted commas, newline=""), json round-trips + live fetch, sqlite3 CRUD, regex + datetime cleaning Journal date|text → JSON → SQLite arc
6 · Tooling & Quality Layout + venv + pip, argparse CLIs, logging levels, pytest asserts/fixtures, pdb/breakpoint() discipline Logged greeting CLI
7 · Power Tools Writing + stacking decorators with wraps (timer/retry), custom with + @contextmanager, timed/logged resources Logged retry decorator
8 · Capstones A) CLI file tool, B) CSV→SQLite reporter, C) tested mini-API — spec → build order → tests → extensions 3 portfolio programs (200–400 lines)
Appendices Regex quick-ref, itertools cheat-sheet, error/pytest field guide + where-next lanes Forever references

Total in-app: 44 lessons, 139 runnable boxes + 29 static references, 6 quizzes (30Q), 21 exercises with solutions, 3 capstones, appendices A–C.


🧪 Interactive superpowers

Same engine as Foundations, tuned up:

  • ▶ Run boxes + >_ console sharing one Python session; Ctrl+Enter runs, ↻ Reset gives fresh state, edits auto-save.
  • Predict → Trace → Run — solutions show trace tables, not just answers.
  • Quizzes that teach — Check answers → explanations → Try again, 🏆 on aces.
  • Exercises with dignity — TODO starter → <details> hints → hidden solution → 🚀 +feature / +robustness / +ship extensions.
  • Callouts everywhere — 💡 why-it-matters (real-world reason), ✅ tips, ⚠️ footgun warnings, 🍪 systems analogies, 🐞 crash labs (broken box → read the last line first → fix in <details>).
  • Progress that survives — sidebar, progress bar (x / 44 lessons), per-lesson checkmarks, dark/light, all local.

🖥️ Two ways to run it (in detail)

1. Browser (start here — zero install)

python-intermediate.html  →  double-click / drag into browser
  • First load needs internet once (~10 MB engine, then cached). After that: fully local, works offline.
  • input() is a pop-up dialog; Cancel = EOFError (Module 0 teaches handling it).
  • Files live in a sandboxed in-memory filesystem and vanish on tab close. Desktop/terminal files persist.
  • True while True: / list(infinite_generator) freezes the tab — reload, code is saved. Infinite sources only ever feed islice/counters/break in this course.
  • The pyfetch, micropip, breakpoint(), and pytest boxes are terminal/browser-only concepts: runnable where they belong, reference elsewhere, never faked.

Supported browsers: current Firefox, Chrome, Edge, and Safari on Windows, macOS, Linux, and Chromebook.

2. Desktop edition (for the real thing — native window)

Same course, same content (parsed live from the HTML), native Qt window via PySide6. Files persist in ~/.pyintermediate/workspace/.

pip install -r requirements.txt   # or: pip install PySide6
python3 py-intermediate.py

Keep py-intermediate.py in the same folder as python-intermediate.html.

Desktop differences worth knowing:

  • Code runs in a real Python subprocess (the interpreter you launched with): real argv, real files/SQLite in workspace/, real pip/pytest.
  • input() is still a pop-up dialog; Cancel raises EOFError, just like the browser.
  • Runaway program? ▶ Run becomes ■ Stop; ↻ Restart clears variables (files stay).
  • Boxes using pyodide/micropip/pyfetch/breakpoint()/pytest render as reference with a "run in terminal" note. numpy works after pip install numpy.
  • The console shares variables with the lesson boxes, exactly like the browser.
  • State dir ~/.pyintermediate/ is fully separate from Foundations' ~/.pycourse/ — run both courses side-by-side safely.

🔒 Privacy & requirements

  • Requirements: Any modern browser. Desktop edition needs Python 3.9+ and pip install PySide6. Terminal work needs Python 3.9+ and a venv (Lesson 0.3).
  • Privacy: Code runs locally. No telemetry, no account, no server. Progress lives in your browser (localStorage, pyi:* keys) or ~/.pyintermediate/ for desktop.
  • Offline: Yes, after first engine download. The live-fetch box (5.3) and micropip box (6.1) need internet on purpose and degrade to local samples offline.

🛠️ Desktop troubleshooting

  • App won't start / ModuleNotFoundError: PySide6: install it first (see Quick start). On Linux you can also use your package manager (apt / dnf / pacman).
  • pip install fails with externally-managed-environment: that's PEP 668 — normal on Debian/Ubuntu/MX Linux/Python 3.11+. Don't pass --break-system-packages; instead use sudo apt install python3-pyside6, or install into a venv (python3 -m venv .venv && .venv/bin/pip install PySide6), or pipx.
  • Emoji or symbols show as boxes (□): install an emoji font, then restart the app:
    • Ubuntu/Debian: sudo apt install fonts-noto-color-emoji
    • Fedora: sudo dnf install google-noto-emoji-color-fonts
    • Arch: sudo pacman -S noto-fonts-emoji
    • Windows: Segoe UI Emoji ships with the OS (nothing to do).
    • macOS: Apple Color Emoji ships with the OS (nothing to do).
  • Wayland vs X11 (Linux): the app runs on both. If your session has Qt issues, try QT_QPA_PLATFORM=xcb python3 py-intermediate.py to force XWayland.
  • Where are my files? Desktop lesson programs write to ~/.pyintermediate/workspace/ and persist. Browser files are in-memory and vanish on tab close.
  • Window icon missing? Keep course-icon.svg next to py-intermediate.py (or next to the HTML). The app falls back to the embedded favicon automatically.
  • A box says "run in terminal": that's a pyodide/micropip/pyfetch/breakpoint()/pytest box doing its job — run that one in your pywork venv per the lesson.

👩‍💻 Who is this for?

Perfect if you are:

  • A David's Python Foundations graduate (or equivalent: ~100-line programs feel easy)
  • A self-taught scripter whose files all live in one folder and break when they grow
  • A student who wants portfolio programs with tests, not just snippets
  • A tinkerer who learns by breaking and fixing (there are 19 crash labs waiting)

You need: Foundations-level fluency (Lesson 0.2 checks it in 10 minutes), Python 3.9+ on your machine for the terminal half, and willingness to type.

After you finish you will be able to:

  • Write 200–400-line multi-file programs with tests and CLIs
  • Replace loops with comprehensions, generators, and stdlib tools (itertools, collections, pathlib, sqlite3)
  • Design small object models (dataclasses, properties, custom exceptions, composition)
  • Run Python like a professional: venvs, argparse, logging, pytest, tracebacks, pdb
  • Read decorators and context managers fluently — and write your own

✅ How to get the most out of it

  1. Type, don't paste. Your fingers learn too.
  2. Predict, then trace, then Run. Wrong guesses teach the most.
  3. Do exercises before opening solutions. Struggle is the feature.
  4. Break things weekly. Feed strings to int(), delete wraps, list() an infinite (once!).
  5. Keep the console open. Answer every "what does this do?" in 5 seconds.
  6. Finish the 3 capstones. Then add one extension each — that's your portfolio.
  7. When stuck: read last traceback line → print() the data before the crash → check Appendix C → ask the console.

❓ FAQ

I haven't done Foundations. Can I start here? Take Lesson 0.2's diagnostic first. 7+/10: welcome aboard. Below that, Foundations Modules 2–6 will pay you back fast — this course assumes them fluent.

Why two machines (browser + terminal)? Concepts click fastest with zero setup (browser). Real programs need files that persist, CLIs with real argv, venvs, and pytest (terminal). The badges (🟢🟡🔴) always tell you where you are.

Where did my files / progress go? Browser: in-memory filesystem (cleared on tab close) + localStorage (pyi:*) for edits and checkmarks. Desktop: ~/.pyintermediate/workspace/ persists across runs.

Can I use pip, numpy, requests? On your PC / desktop edition: yes, everything real. In the browser tab: micropip installs real wheels, numpy works if installed, fetching uses pyfetch (Lesson 5.3) instead of sockets. Each edition's boxes say which.

I froze the tab — did I break it? No. Reload; code is saved. Infinite things only ever feed islice, counters, or break-guarded loops in this course — if you removed the guard while tinkering, that's a successful experiment.

Is this Python 2 or 3? Python 3.12 (dataclasses, pathlib, f-strings, zoneinfo-era stdlib). No Python 2-isms.


🚀 After the course

Three lanes from Appendix C — pick the one whose programs excite you:

  • Web: serve Capstone C properly → HTTP deeply → one framework (Flask/FastAPI/Django)
  • Data: 10k-row reporters → SQL deeply → pandas, then charts from Capstone B
  • Automation: scheduled jstat-style tools → argparse mastery → packaging, cron/systemd

As the course says at the end: You have three tested programs now. Go build the fourth. 🐍


David's Python Intermediate · single HTML file · Python 3.12 in your tab via Pyodide · no data ever leaves your browser
Open python-intermediate.html and press ▶ Run. Happy hacking!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages