Page 62 - Programming the Raspberry Pi Getting Started with Python
P. 62
converter. You can run and experiment with the two classes together by running
05_03_converters_final.py:
It’s a simple matter to convert these two classes into a module that we can use in other programs. In
fact, we will use this module in Chapter 7, where we attach a graphical user interface to it.
To turn this file into a module, we should first take the test code off the end of it and then give the
file a more sensible name. Let’s call it converters.py. You will find this file in the downloads for this
book. The module must be in the same directory as any program that wants to use it.
To use the module now, just do this:
Summary
Lots of modules are available for Python, and some are specifically for the Raspberry Pi, such as the
RPi.GPIO library for controlling the GPIO pins. As you work through this book, you will encounter
various modules. You will also find that as the programs you write get more complex, the benefits of
an object-oriented approach to designing and coding your projects will keep everything more
manageable.
In the next chapter, we look at using files and the Internet.