You can not.
Instances only inherit the methods and attributes of the parent class, not the attributes of the instance. You should not confuse them.
strauss.familyName is an attribute of an instance of a Family instance. Person instances will have their own copies of the familyName attribute.
You usually code the Person constructor to accept 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 reference the Family instance:
class Person(object): def __init__(self, personName, family): self.personName = personName self.family = family
where Person no longer inherited from Family . Use it as:
strauss = Family('Strauss') johaness = Person('Johaness', strauss) richard = Person('Richard', strauss) print johaness.family.familyName
Martijn pieters
source share