I’m currently programming a game in python. I have a main class (engine.py), and many subclasses. The main class has some important variables like the player. When I now am in a subclass, and want to access another variable or function, it often looks like this:
self.handleToEngine.player.playerObj.animationHandler.doSomething()
Is there a way to shorten this? I don’t believe the performance is that good, and it’s no clean code.
The attribute chain reflects your class structure, so of course you could refactor that if it makes sense. Also, in Python 2.2 or later, you can use
__slots__to improve access to member data, with some caveats.