# pythonDemo **Repository Path**: ursusit/pythonDemo ## Basic Information - **Project Name**: pythonDemo - **Description**: python学习笔记。 - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-18 - **Last Updated**: 2026-10-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Python for Production: a runnable tutorial An **executable, test-verified** Python course for experienced engineers who are new to Python. The distinguishing property: the writing contract requires every conclusion in the prose to have a machine check - an `assert` inside the example plus a test that really runs it - and anything that could not be verified locally is labelled as such where it appears rather than stated as fact. Each example can be executed directly (the sole exception being `18_capstone/18_cli.py`, a command-line entry point whose required `--config` flag is documented in its own chapter), and each chapter has its own test suite. All examples work offline - no internet access, no external database, no hard-coded absolute paths, and no `sleep()` used to make timing correct. The written content is primarily in Chinese; see `docs/学习路线.md` for the full roadmap. ## Quick start Requires **Python 3.12 or newer** - the syntax is 3.10-compatible, but the test suite is not (see Verification below). ```bash python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate python -m pip install -e ".[dev,web]" python -m pytest -q python -X utf8 01_orientation/01_runtime_anatomy.py ``` ## Layout 18 numbered chapters across three tracks: - **01-08 language core** - object model and name binding, functions and closures, iterators and generators, attribute machinery and descriptors, exceptions and resource ownership, the import system, type annotations. - **09-13 engineering** - environments and packaging, testing and quality gates, logging and profiling, concurrency models and how to choose one, file handling, encodings and serialization formats. - **14-18 production** - sockets through HTTP clients to databases and ORM, a FastAPI service with layering and tests, containers and CI/CD, a catalogue of counter-intuitive behaviours, and a capstone CLI project. Each chapter directory contains `README.md` (the prose), `NN_topic.py` (runnable examples) and `test_NN_topic.py` (tests asserting every claim made in that prose). ## Verification Everything is measured on CPython 3.12.0 / Windows 10 (1451 passed, twice in a row), and independently re-run end to end on CPython 3.13.13 and CPython 3.14.5. The **syntax** baseline is 3.10 - every `.py` file compiles under 3.10 and ruff/mypy check against it - but the **runtime** floor is 3.12: measured with the same tool versions as `.venv` (pytest 9.1.1 / ruff 0.16.4 / mypy 2.3.1), 3.10 has 54 failing cases plus 2 collection errors and 3.11 has 14, while 3.12.0 / 3.13.13 / 3.14.5 pass in full. The causes fall into three groups: some chapters need runtime features that only arrive in 3.11+ (`typing.NotRequired`, `tomllib`), warning categories moved between versions (an invalid escape is only a `DeprecationWarning` on 3.10), and error messages change wording. So `requires-python` and the install guide both say **3.12**; the "3.10 baseline" only means no newer *syntax* is used. Case counts move as content is added or removed - the number given here is the one from the same run as the quality gates; treat any other interpreter's count as "whatever `python -m pytest -q --collect-only` prints on your tree". Scale, measured with the same gate run: 130 runnable examples (top-level `NN_topic.py` files; chapter support modules and one chapter-level `conftest.py` are not counted), 108 test files, 1451 test cases. Content that could not be verified locally (for example `docker build`, which needs Docker) is explicitly flagged as unverified in the relevant chapter instead of presented as fact. ## Contributing Read `docs/CONVENTIONS.md` first. Pull requests must pass `pytest`, `ruff check` and `mypy`. ## Legacy material The repository's original scattered notes live in `archive/legacy/`. They are excluded from all quality gates and kept only as source material; several of their real defects are cited as counter-examples in the corresponding chapters.