Chapter 13

Special Class Methods

Heh, asking a bunch of Buddhists to judge “good” and “bad”, good luck!

—Brian Zbriger (http://members.aol.com/dowcet/)


Running del.py
Figure 1.
Running spam.py
Figure 2.

Example Programs

There are several example programs for chapter 13:  download chapter13.zip.

  1. del.py
  2. parrots.py
  3. spam.py


Implement the rest of the numeric special class methods for class spam, working from Listing 13.4 as a base.

Implement more special class methods for class parrot, working from Listing 13.5; while the code shown does include all but two of the sequence and mapping types, you might wish to build a __sub__() method, for example, which looks through the self string and subtracts the other string from self if it matches.  At the least, you should implement the __cmp__() method.

See if you can come up with a simpler way than try - except - else to build the __setattr__() method in the egg class in Listing 13.6.

You can download the code for mayalib, which contains classes and functions for manipulating dates and numbers in the Mayan calendar at The Software Download Page.  You’ll also find information about the Mayan calendar itself at the default page for the same web site, http://www.pauahtun.org/.

Valid HTML 4.01 Transitional