Errata for Object-Oriented Python

(As of  4/2/23)

 

Important notice about pygame

As of Python 3.11, a new branch of pygame, named "pygame-ce" (community edition), must be used.  (The details of this are too complex to go into here.)  In all printings of Object-Oriented Python, there are these installations instructions for the pygame package:

Page 90:  Installing the pygame package.  The page says to enter these commands at the command line:

python3 -m pip install -U pip --user
python3 -m pip install -U pygame --user

To install the community edition of pygame, you must first uninstall the older version of pygame if you have already installed it. Here are the updated commands that you should use at the command line.:

python3 -m pip install -U pip --user
python3 -m pip uninstall -U pygame --user
python3 -m pip install -U pygame-ce --user

After installing pygame-ce, you do NOT need to change anything to use the example code from the book. In fact, the import statement:

import pygame

will work to bring in the new pygame-ce package.

 

Updates to 2nd and 3rd printing

 

 

Page 208:  The code for Listing 9-10, has an error in the last line.  The line that reads:

print('The sum of 5/2 and 500/2\n, oFraction5 + oFraction6)

should be:

print('The sum of 5/2 and 500/200\n, oFraction5 + oFraction6)

Also, in the section below that shows the generated output, the line:

The sum of 5/2 and 500/2

should be:

The sum of 5/2 and 500/200

=======================================================================================

 

Updates to 1st printing

 

Page xxii: "Python Version(s) and Installation" says:

"All the example code in this book was written and tested using Python versions 3.6 through 3.9.  All the examples should work fine with version 3.6 or newer."

This should be:

"All the example code in this book was written and tested using Python version 3.9.  All the examples should work fine with version 3.9 or newer."

 

 

Page 6:  In Listing 1-1, near the end of the code, the line that reads:

currentCardValue = nextCardValue  # don't need current card suit

should be the two lines:

currentCardValue = nextCardValue
currentCardSuit = nextCardSuit

 

Page 37:  In Listing 2-7, in line 13 of the TV.py class code, the line that reads:

self.volume = self.VOLUME_MAXIMUM //  # integer divide

should be:

self.volume = self.VOLUME_MAXIMUM // 2  #integer divide

 

Page 63:  In Listing 4-3, the line that reads:

print('After depositing 100, the user's balance is:', usersBalance)

should be:

print("After depositing 100, the user's balance is:", usersBalance)

The same error should also be corrected on page 65 in Listing 4-4 , and on page 67 in Listing 4-5.

 

Page 101:  When describing how to build a path, the following line:

pathToBall = BASE_PATH + 'images/ball.png'

should now be:

pathToBall = BASE_PATH / 'images/ball.png'

 

Page 123:  In Listing 6-1, the line labelled with (5) should be outdented by one level.

 

Page 154:  In the code snippet for using a Button object, the last line:

oButton.draw()

should be indented one level.

 

Page 191:  Listing 9-5, has two errors.  The line that reads:

for i in range(0, N_SHAPES):

is shown indented by one character, but it should not be indented at all.

Also, in the MOUSEBUTTONDOWN code, the line:

newText = 'Clicked on a ' + theType + ' whose area is' + area)

should be:

newText = 'Clicked on a ' + theType + ' whose area is ' + area

 

Page 202:  In Listing 9-8, the line that reads:

if isInstance(oOther, Vector):  # multiply two vectors

should be:

if isinstance(oOther, Vector):  # multiply two vectors

 

Page 205:  The code for Listing 9-9, has two errors.  The line that reads:

print('Vector 2 times 5: ', v1 * 5)

should be:

print('Vector 1 times 5: ', v1 * 5)

Also, in the section that shows the generated output, the line

Vector 2 times 5: This vector has the value(15, 20)

should be:

Vector 1 times 5: this vector has the value(15, 20)

 

Page 206:  In Listing 9-10, the code of the __add__() method makes a call to math.lcm().  This does work.  However, math.lcm() is only supported in Python 3.9 and later.  The introduction to the first eedition of the book says that all code works with Python versions 3.6 and later, but see the first erratum in this list.

 

Page 208:  The code for Listing 9-10, has an error in the last line.  The line that reads:

print('The sum of 5/2 and 500/2\n, oFraction5 + oFraction6)

should be:

print('The sum of 5/2 and 500/200\n, oFraction5 + oFraction6)

Also, in the section below that shows the generated output, the line:

The sum of 5/2 and 500/2

should be:

The sum of 5/2 and 500/200

 

Page 223:  In Listing 10-4, the parameter value is listed twice, at positions 4 and 12.  The line:

justified='left', value=None, currencySymbol='$',

should be:

justified='left', nickname=None, currencySymbol='$',

 

Page 250:  In Listing 11-3, the last line:

oSample1.howManyObject()

does work correctly.  But a better example would be to access the variable associated with the class directly and therefore should be:

print('Number of objects:', Sample.nObjects)

 

Page 256:  In Listing 11-6, after the line:

self.nMissed = 0

there should be an additional line:

self.score = 0

 

Page 271:  In Listing 12-2, the last line:

self.deckList.insert(0, oCard)

should be:

self.playingDeckList.insert(0, oCard)

 

Page 296:  In Listing 14-1, the parameter list for the __init__() method:

def __init__(self, window, loc, picPaths durationsPerImage):

is missing a comma.  It should be:

def __init__(self, window, loc, picPaths, durationsPerImage):

 

Page 303:  In Listing 14-4, in the line that defines oWaterAnimation, the line that says:

5, 50, 192, 192, .05)

should be:

50, 192, 192, .05)

 

Page 305:  In the second line in the interface of the Animation class, the line:

loop=False, nickname=None, callBack=None, nIterations=1)

is missing a parameter.  It should be:

loop=False, showFirstImageAtEnd=True, nickname=None, callBack=None, nIterations=1)

 

Page 306:  In the third line in the interface of the SpriteSheetAnimation class, the line:

autoStart=False, loop=False, nickname=None,

is missing a parameter.  It should be:

autoStart=False, loop=False, showFirstImageAtEnd=True, nickname=None,

 

Page 320:  About half way down the page, in the discussion labeled "Scenes", there is a reference to the filename:

ExampleScene.py

has an incorrect name.  It should be:

SceneExample.py