Finding a module's sub modules at runtime

Joshua J. Kugler joshua at eeinternet.com
Thu Mar 29 15:07:02 EDT 2007


On Thursday 29 March 2007 07:33, Alex Martelli wrote:

> Joshua J. Kugler <joshua at eeinternet.com> wrote:
> 
>> still be nicely portable.  It just seems that since Python is gathering
>> that information anyway, it should make it available without me having to
>> walk the directory tree.
> 
> Sorry, where is Python "gathering that information anyway"?  Unless I'm
> mistaken, Python by default does not walk directory trees of subpackages
> -- what makes you think it does?

Hmm...right: dynamic language, runtime binding.  It would go out and find
whether or not Module1.Module2 existed only when import was called.  Sorry,
my bad.  I am assuming, however, that the help function walks the directory
tree, or else I would not get output like this:

>>> import ModTest
>>> help(ModTest)
Help on package ModTest:

NAME
    ModTest

FILE
    /usr/local/lib/python2.4/site-packages/ModTest/__init__.py

PACKAGE CONTENTS
    AModule
    BModule
    CModule

Thanks for the clarification.

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com




More information about the Python-list mailing list