Next / Previous / Contents / Shipman's homepage

28. class Box: Define a rectangle

An instance of this class represents a rectangle, defined by its width and height.

fosox.py
# - - - - -   c l a s s   B o x

class Box(object):
    '''Represents the dimensions of a rectangle.

      Exports:
        Box(wide, high):
          [ wide and high are FoDim instances ->
              return a new Box representing those dimensions ]
        .wide:      [ as passed to constructor ]
        .high:      [ as passed to constructor ]
        .__str__(self):   [ return self as a string ]
    '''

28.1. Box.__init__()

fosox.py
# - - -   B o x . _ _ i n i t _ _

    def __init__(self, wide, high):
        '''Constructor.
        '''
        self.wide, self.high = wide, high