Object-Oriented Design Frequently Asked Questions


Where do I find answers to questions about Python ?

Tutorials, references, and links kan be found at http://www.python.org.

How does one check whether an object c is of "type" C ?

  1. For builtin types, one can use the operator type(). For example:
         >>> type(2)
         <type 'int'>
    If we declare a class C and create an instance c as shown below, type() will give rather general information:
        >>> class C:
        >>> c=C()
        >>> type(C)
        <type 'classobj'>
        >>> type(c)
        <type 'instance'>
  2. If we want to check whether c is an instance of class C, we can use the test
        >>> isinstance(c, C)
    This will evaluate to True if c is an instance of class C or any of C's sub-classes.

    In recent versions of Python, it is possible to test for basic types with isinstance as in isinstance(1,int), isinstance(1.2,float) and isinstance([1,2],list).

How do I generate nice HTML from Python source code ?

  1. Colorized pretty-printing for file code.py can be done with
    enscript -Whtml -Epython --color code.py -o code.html
  2. An API document for file code.py can be generated with
    pydoc -w code


MUST we work in teams of 2 ?

You must work in a team of exactly two people. Previous experience has shown that after the initial transient chaos of finding a partner, this works really well. Try to find a team partner after class or by sending a message to the entire class on WebCT. Remember that "pair programming" requires you to actually work together (same place, same time). You may form different teams for different assignments.