[Python-Dev] Re: Python-Dev digest, Vol 1 #2276 - 14 msgs

Kevin Butler kbutler@campuspipeline.com
Fri, 31 May 2002 14:35:04 -0600

I asked about publishing a module & submodules in one .py file, and showed an 

Guido responded:
 > I think it's much better to split it up in multiple files than to use
 > all those hacks.  Those hacks are hard to understand for someone
 > trying to read the code.

I agree - I don't like the look of that code for user-level code. However, to 
me the complexity was that I had to show the implementation (and the dynamic 
"getMethods" call instead of explicitly listing methods to publish).

If the 'imp' module had a 'publish_module' method that created a module (with 
an optional dictionary?) & registered it in sys.modules, client code becomes 
very simple, clear, and can be very explicit:

assertions = imp.publish_module( __name__ + ".assertions" )
_a = Assertions()
assertions.failUnless = _a.failUnless
# ...

Is that more pleasant, or is the whole idea of organizing portions of a single 
file into submodules unacceptable?