python - Link two classes together by variables -
i learning python couple different books learn python hard way. i trying better understand classes , ran example : class dog(object): def __init__(self, name): self.name = name self.legs = 4 self.carry_weight = 0 class person(object): def __init__(self,name): self.name = name self.pet = none self.weight = 0 rover = dog("rover") rover.carry_weight = 180 frank.pet = rover print frank.name print frank.pet.legs if frank.weight < frank.pet.carry_weight: print "yes, frank can ride dog %s around neighborhood" % frank.pet.name so learned can link 2 instances of class , call attributes 1 other. wanted add attribute owner = none under dog. , when link frank rover links rover frank owner if know rover can pull frank. what have come idea: def assign_pet(self, petsname): self.pet = petsname petsname.owner = self.name this seems work fine wanted know if best way go this.