All paths

Python with real habits

Advanced Python on a Raspberry Pi, after Python from zero: modules, classes, exceptions, files and logging, tests with plain assert, generators, and a sensor logger that uses them all.

Raspberry Pi 4 Model BFree7 lessons6 h4 chapters2,688 XPCoding · Advanced+250 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 6 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

Classes

Classes and objects on a BME280: the driver class you already use, a Reading class of your own with methods and __str__, an object that remembers the highest temperature, and inheritance.

Open it in the simulator
Chapter 2 project

Files and logging

Write a knob's readings to a file and read them back, a CSV any spreadsheet opens, the logging module with its levels in place of print, and a log file: what the Pi's engine supports, and what lasts.

Open it in the simulator
Chapter 3 project

Generators

yield and next, a generator that streams knob readings forever, a moving average built as a pipeline of generators, islice to take just a few, and generator expressions.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Structure

Split code into modules, and bundle data with its functions in classes.

  1. Open265 XP

    Modules

    Split a program into files: the OLED driver you have been importing all along, the standard library, a module of your own in a new tab, and what __name__ == "__main__" is for.

    0 of 6 steps

  2. ProjectLocked530 XP

    Classes

    Classes and objects on a BME280: the driver class you already use, a Reading class of your own with methods and __str__, an object that remembers the highest temperature, and inheritance.

    0 of 6 steps

Chapter 2

When things go wrong

Exceptions, files and logs: code that survives a loose wire and tells you what happened.

  1. Locked265 XP

    Exceptions

    Read a traceback, catch the I2C error a missing chip really raises, scan two addresses without crashing, raise an exception of your own, and clean up with else and finally.

    0 of 6 steps

  2. ProjectLocked530 XP

    Files and logging

    Write a knob's readings to a file and read them back, a CSV any spreadsheet opens, the logging module with its levels in place of print, and a log file: what the Pi's engine supports, and what lasts.

    0 of 6 steps

Chapter 3

Craft

Tests with assert, and generators that stream data forever.

  1. Locked265 XP

    Tests with assert

    No pip and no pytest, so tests are plain assert: catch a real off-by-one in a voltage conversion, test the edges, write a ten-line test runner, and let a failing test drive a fix.

    0 of 6 steps

  2. ProjectLocked530 XP

    Generators

    yield and next, a generator that streams knob readings forever, a moving average built as a pipeline of generators, islice to take just a few, and generator expressions.

    0 of 6 steps

Chapter 4

Boss project

A sensor logger with a screen, a CSV and a log, built from every habit in the course.

  1. Locked303 XP

    Project: a sensor logger

    The boss project: a BME280 and an OLED on one I2C bus, a logger module with a Sample class and a generator of samples, a test before anything is trusted, a CSV log, the latest reading on the screen and a warning when it gets hot.

    0 of 7 steps

Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Structure

  1. ModulesSplit a program into files: the OLED driver you have been importing all along, the standard library, a module of your own in a new tab, and what __name__ == "__main__" is for.
  2. ClassesClasses and objects on a BME280: the driver class you already use, a Reading class of your own with methods and __str__, an object that remembers the highest temperature, and inheritance.
Chapter 2

When things go wrong

  1. ExceptionsRead a traceback, catch the I2C error a missing chip really raises, scan two addresses without crashing, raise an exception of your own, and clean up with else and finally.
  2. Files and loggingWrite a knob's readings to a file and read them back, a CSV any spreadsheet opens, the logging module with its levels in place of print, and a log file: what the Pi's engine supports, and what lasts.
Chapter 3

Craft

  1. Tests with assertNo pip and no pytest, so tests are plain assert: catch a real off-by-one in a voltage conversion, test the edges, write a ten-line test runner, and let a failing test drive a fix.
  2. Generatorsyield and next, a generator that streams knob readings forever, a moving average built as a pipeline of generators, islice to take just a few, and generator expressions.
Chapter 4

Boss project

  1. Project: a sensor loggerThe boss project: a BME280 and an OLED on one I2C bus, a logger module with a Sample class and a generator of samples, a test before anything is trusted, a CSV log, the latest reading on the screen and a warning when it gets hot.
Keep going

The next course on your track

Python with real habits is part of the coding track, a ladder of courses from zero to expert.

Next course

Data structures and algorithms

The ideas every programmer is asked about, built and measured on an Uno: big O, linked lists, stacks and queues, hash maps, sorting and binary search. Ends with a leaderboard that needs them all.

Open the next course
Track

Coding track

Python and C++ from your first print to classes, tests and state machines. Every program runs on a simulated board, so a bug is something you can see.

See every course on the track
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Python with real habits

Is Python with real habits free?

Yes. All 7 lessons of Python with real habits are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Python with real habits take?

About 6 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Classes, Files and logging and Generators.

Where do I start?

With "Modules", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.