I'm currently in the middle of porting a fairly large Perl The problem is that it uses little Perl tricks to make its code available for use
ing. I've done about the same with Python, making the codebase one big module for import
ing. I've had a firm grasp of Python for a long time, but I have no experience with large projects written in Python that need to access other parts of itself while maintaining an internal state.
I haven't yet tried simply importing the entire thing in one line (import core
), but I know I'm currently not doing things in the best of ways. Here's an example from the master script that sets everything in motion:
self.Benchmark = Benchmark(self)
self.Exceptions = Exceptions
self.Settings = Settings(self)
self.Cache = Cache(self)
self.Deal = Deal(self)
self.Utils = Utils(self)
self.FileParsers = FileParsers(self)
self.Network = Network(self)
self.Plugins = Plugins(self)
self.Misc = Misc(self)
It works, but I'm not happy with it. Right now, the master class script imports each piece of the core
module and creates an instance of the contained classes, passing itself as an argument to __init__
in those classes. Like so:
class FileParsers:
def __init__(self, parent):
self.parent = parent
Now the code in that class can access the entire rest of the codebase through the parent class.
self.parent.Settings.loadSysConfig()
So my question is this: considering the above, what would be the best way to reorganize the project and refactor the code so that it retains its current ability to access everything else? The code is very noncritical, so I'm not that worried about internal data integrity, I just don't like having to go through the parent class in such an ugly way. And those long chains slow the code down as well.
EDIT: Whoops, forgot these: links to the SVN repos for both project. Mine is here, and the project I'm porting is here.