12

Chapter 12

More OOP Concepts


Mistakes are almost always of a sacred nature.  Never try to correct them.

—Salvador Dali

Figures

Importing out of order
Figure 1.
Correct importing
Figure 2.
Running roman.py
Figure 3.
Running today-roman.py
Figure 4.
Running today-roman.py
Figure 5.

Example Programs

There are several example programs for chapter 12:  download chapter12.zip.

  1. imptest1.py
  2. imptest2.py
  3. now.py
  4. roman.py
  5. today.py
  6. today-roman.py

Exercises

Find out about Python’s name mangling rules at the usual place:  http://www.python.org/.

Write the mixin class described at the beginning of the Multiple Inheritance section that provides a __repr__() method to any class that inherits from it.  Modify the today class to take advantage of your mixin class.  Hint:  Mark Lutz and David Ascher cover this topic in their book, Learning Python (now in its second edition).

You may need to change the name of the method from __repr__ to something else if you want today to continue to display the date it represents.

Track down all the symbols or tokens that have been used over the last 2000 years to build Roman numerals; decide on easy ways to represent these tokens when your program is limited to the command line interface.  See if you can figure out a way to read in a Roman numeral, decode it and print out the equivalent base 10 number.

Rewrite class roman to use the shortcuts described.  While you’re at it, work on coming up with a less wordy way of converting from a base 10 number into a Roman one.  Hint:  use lists or arrays.

For more on the Buddhist conception of no-self, see Buddhadasa Bhikkhu’s Heartwood of the Bodhi Tree:  The Buddha’s Teaching on Voidness.


Valid HTML 4.01 Transitional