Your Cart
Loading

Code Clinic - The Build - Book 2: Modules & Packages

On Sale
$12.00
$12.00
Added to cart

One giant file is a dead end. This book shows what real Python projects do instead. First the module, which is nothing more than a .py file whose functions another file can import. Then the scaling problem: what happens when twenty parsing functions and a pile of helpers all live in one place, and why folders are the answer. You build a package, a folder of modules held together by __init__.py, and you look inside that file to see what it is actually for. Three ways to import get set side by side, so you can tell import module from from module import name and know when each one reads better. Absolute imports come next, then relative imports and the dot notation that walks up and down your own folder tree. The book closes with the __main__ guard, the small if statement that lets a file run on its own as a script and still be imported quietly by something else. The example project is a set of message parsing modules, the shape that sits behind real medical record systems.


Twenty A4 pages, in full colour. Written in short sentences and plain English, for readers whose first language is not English and clearer for everyone else because of it.


Every code example in this book was run before the page was printed, so the output you read is the output you get. Instant PDF download. By M.R. Sterling.


You will get a PDF (887KB) file