""" student_faculty.py a (very) simple inheritance example, along with both a class variable Jim M | Nov 2012 """ class Person(object): """ People with names. >>> str(Person('John')) 'Person: John' """ population = 0 def __init__(self, name="John Smith"): self.name = name Person.population = Person.population + 1 def get_name(self): return self.name def set_name(self, newname): self.name = newname def __str__(self): return "Person: " + self.name class Faculty(Person): def __init__(self, name): Person.__init__(self, name) def __str__(self): return "Faculty: " + self.name class Student(Person): def __init__(self, name): Person.__init__(self, name) def __str__(self): return "Student: " + self.name def _test(): from doctest import testmod testmod() def main(): sally = Person("Sally") dr_bob = Faculty("Dr. Bob") fred_freshman = Student("Fred Freshman") print sally print dr_bob print fred_freshman print "total population is " + str(Person.population) if __name__ == '__main__': _test() main()