Importing dynamically loaded modules (in packages)?

holger krekel pyth at devel.trillke.net
Wed May 1 10:10:18 EDT 2002


On Wed, May 01, 2002 at 03:30:16AM +0200, Irmen de Jong wrote:
> "holger krekel" <pyth at devel.trillke.net> wrote in message
> news:mailman.1020213066.536.python-list at python.org...
> 
> > > "import Package.TestModule" still doesn't work: ""no module named
> TestModule""
> > > How can I correct this?
> >
> >     sys.modules['Package.TestModule'] = TestModule
> >
> > after that you should be able to do
> >
> >     import Package.TestModule
> 
> Ouch... isn't that cheating? I mean, the Module name is "TestModule",
> not "Package.TestModule".

Yes, it's the blessed way of cheating, though. 
See 'os' and 'os.path' for example. 

The package concept falls a bit out of python.  
After rereading the docs at 
http://www.python.org/doc/essays/packages.html
it doesn't feel like a thoroughly thought out concept
(compared to so many other things in python).

There is no 'package' object to start with and package
functionalities are not encapsulated anywhere. 
So it seems approriate to think of a package as a 
concept of nested modules and accessing them with 
respect to directory structure and filesystem-coupled
initialization.

imho Python3 should have a better grip
on packages. 

Is their already something underway?
Does anybody disagree?

take care,

    holger





More information about the Python-list mailing list