Creating our first Python program and running loops

Loops are one the most common programming functions, and very useful when doing things such as collecting readings over and over and reading through log files or sensor data. In this recipe, we will look at the different ways in which Python handles loops.

Getting ready

We're going to work with Raspbian's built-in Geany IDE:

  1. Create a new Python program with File | New (With template) | main.py. Then, save it as rpz_log_analysis.py. We will use add to this program throughout the chapter.
  2. If you haven't been logging your own temperature data or Raspberry Pi restarts, it is included in the source code for this book, which you can pull with Git. Make a note of where rpz_temp.log and rpz_startup.log

Get Raspberry Pi Zero Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.