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:
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.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
andrpz_startup.log
are (hint: usefind
!), or copy them into the/var/logs/
directory of your Raspberry Pi Zero.If you want to start with the completed code for this recipe, it is named
rpz_log_analysis_loops.py
in the/ch4/
directory.
How to do it...
Replace the default...