Module Structure/Import Design Problem
stef.mientki at gmail.com
Thu Nov 20 19:20:36 CET 2008
> I am in a situation where I feel I am being forced to abandon a clean
> module structure in favor of a large single module. If anyone can save
> my sanity here I would be forever grateful.
> My problem is that classes in several modules share a common base
> class which needs to implement a factory method to return instances of
> these same classes.
> An example to help illustrate what I mean:
> Lets say I have the following modules with the listed classes:
> - baselib.py with BaseClass
> - types.py with TypeA, ...
> - special.py with SpecialTypeA, ...
> Which would be used a bit like this:
>>>> type_a = any_type_instance.get_type("TypeA")
>>>> special_type = type_a.get_type("SpecialTypeA")
> Again, I can get around this by dumping everything in to one module,
> but it muddies the organization of the package a bit. This seems like
> a problem that would come up a lot. Are there any design paradigms I
> can apply here?
I'm not an expert, I even don't fully understand your problem,
but having struggled with imports in the past,
I've a solution now, which seems to work quit well.
> - Rafe
More information about the Python-list