我有Family及其继承的Person类。如何familyName从类中获取属性Person?
class Family(object):
def __init__(self, familyName):
self.familyName = familyName
class Person(Family):
def __init__(self, personName):
self.personName = personName
例如,让这些Family和Person对象:
strauss = Family('Strauss')
johaness = Person('Johaness')
richard = Person('Richard')
我想做一些事情,例如:
print richard.familyName
并得到'Strauss'. 我怎样才能做到这一点?