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

(singke) #1

set to 'unknown' and 0 , respectively, on lines 19 and 20.


In Listing 15.6, the object instances themselves are declared on lines 22 through 24. Finally, the
accessors for each object are used to obtain the immutable values of each object class. They are
printed to the screen on line 28 through line 50.


Listing 15.7 shows script1501.py in action. Both the base class and each subclass’s immutable
values are displayed.


LISTING 15.7 Output of script1501.py


Click here to view code image


pi@raspberrypi ~ $ python3 /home/pi/py3prog/script1501.py
A bird has feathers, bones that are hollow and hard-shell eggs.

A barn swallow is a bird that is migratory.
A cliff swallow is a bird that is not migratory.
pi@raspberrypi ~ $

As you can see, the script runs fine. Both the BarnSwallow object and the
SouthAfricaCliffSwallow object are able to inherit data attributes and methods within the
script from the Bird object with no problems.


Many ornithology organizations around the world—such as Cornel’s Great Backyard Bird Count, at
http://www.birdsource.org/gbbc/—seek bird-sighting information. The script1501.py script was
modified to include sighting information and renamed script1502.py.


Listing 15.8 shows the script1502.py script. It now includes methods to obtain flock size
information.


LISTING 15.8 Python Statements in script1501.py


Click here to view code image


1: pi@raspberrypi ~ $ cat /home/pi/py3prog/script1502.py
2: # script1502.py - Record a Swallow Sighting
3: # Written by Blum and Bresnahan
4: #
5: ############ Import Modules ##################
6: #
7: # Birds object file
8: from birds import Bird
9: #
10: # Barn Swallow object file
11: from barnswallow import BarnSwallow
12: #
13: # South Africa Cliff Swallow object file
14: from sacliffswallow import SouthAfricaCliffSwallow
15: #
16: # Import Date Time function
17: import datetime
18: #
19: ################################################
Free download pdf