Apr-19-2018, 07:53 PM
Salmon inherits fish so includes all "fish" variables. The purpose of this is so you change one variable and all of the classes can use the change. To isolate the fish variable you create a separate instance instead of inheriting.
class Fish(): def __init__(self): self.position = [0,0,0]; class Tuna(): def __init__(self): #extra variables here! self.this_fish=Fish() class Salmon(): def __init__(self): #extra variables here! self.this_fish=Fish() obj1 = Salmon() obj2 = Tuna() obj1.this_fish.position = [1,1,1] print(obj1.this_fish.position) print(obj2.this_fish.position)