Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
http://www.birdsource.org/gbbc

Sighting on 2013-11-06
Species: European/Barn Swallow
Flock Size: 7
Sex: unknown
pi@raspberrypi ~ $

Again, for simplicity, the data gathered here is overly simplified. However, to aid in your
understanding of inheritance, subclasses, and object module files, you are going to improve it!


Try It Yourself: Explore Python Inheritance and Subclasses
In the following steps, you will explore Python inheritance and subclasses by
improving the bird-sighting information script, script1502.py. Follow these
steps, to modify the script and create a new base class and subclass:


  1. If you have not already done so, power up your Raspberry Pi and log in to the
    system.

  2. If you do not have the LXDE GUI started automatically at boot, start it now by typing
    startx and pressing Enter.

  3. Open up the LXTerminal by double-clicking the LXTerminal icon.

  4. At the command-line prompt, type nano py3prog/script1503.py and press
    Enter. This command puts you into the nano text editor and creates the file
    py3prog/script1503.py.

  5. Type all the information from script1502.py in Listing 15.6 into the nano editor
    window, pressing Enter at the end of each line. Be sure to take your time here and
    avoid any typographical errors. You can make corrections by using the Delete key
    and the up- and down-arrow keys.


By the Way: Make It Easy
Instead of doing all this typing, you can download script1502.py from
informit.com/register. After downloading the script, simply use it instead of creating
the new script1503.py.


  1. Make sure you have entered the code into the nano text editor window, as shown in Listing
    15.6. Make any corrections needed.

  2. Write out the information from the text editor to the script by pressing Ctrl+O. The script file
    name shows along with the prompt File name to write. Press Enter to write out the
    contents to the script1503.py script.

  3. Exit the nano text editor by pressing Ctrl+X.

  4. At the command-line prompt, type nano py3prog/birds.py and press Enter. This
    command puts you into the nano text editor and creates the file py3prog/birds.py.

  5. Type all the information from birds.py in Listing 15.4 into the nano editor window. You

Free download pdf