I have the Family and its inherited Person classes. How do I get the familyName attribute from the Person class?
You cannot.
Instances only inherit the parent class methods and attributes, not instance attributes. You should not confuse the two.
strauss.familyName is an instance attribute of a Family instance. The Person instances would have their own copies of the familyName attribute.
You normally would code the Person constructor to take two arguments:
class Person(Family):
def __init__(self, personName, familyName):
super(Person, self).__init__(familyName)
self.personName = personName
johaness = Person('Johaness', 'Strauss')
richard = Person('Richard', 'Strauss')
An alternative approach would be for Person to hold a reference to a Family instance:
class Person(object):
def __init__(self, personName, family):
self.personName = personName
self.family = family
where Person no longer inherits from Family. Use it like:
strauss = Family('Strauss')
johaness = Person('Johaness', strauss)
richard = Person('Richard', strauss)
print johaness.family.familyName