Apr-29-2020, 07:49 PM
If getMaxX was a class method it would have to return a class variable.
If this pattern does not work for, you'll need to pass an instance of World to Fish. If all Fish are in the same World, the World attribute in Fish could be a class attribute.
class World: maxX = 100 maxY = 100 @classmethod def set_range(cls, mx, my) cls.maxX = mx cls.maxY = my class Fish(LifeForm): def liveALittle(self) ... if 0 <= newX <= World.maxX: def main(): """Create everything""" World.setRange(10,000, 50,000) red_fish = Fish()World could be a "class only" type class (My TM if nobody else has uses this), or it could be a regular class with some class attributes that are common to all instances.
If this pattern does not work for, you'll need to pass an instance of World to Fish. If all Fish are in the same World, the World attribute in Fish could be a class attribute.
class World: def __init__(self, mx, my): self.maxX = mx self.maxY = my class Fish(LifeForm): world = None @classmethod def set_world(cls, world): cls.world = world def liveALittle(self) ... if 0 <= newX <= self.world.maxX: def main(): """Create everything""" world = World(10,000, 50,000) Fish.set_world(world) red_fish = Fish()