How to: get list of modules in a package

Peter L Hansen peter at engcorp.com
Tue Oct 12 11:05:23 EDT 2004


Dan Perl wrote:
> Is there a direct way to get a list of all the modules in a package, other 
> than using an os.listdir() for the directory of the package?

Given the dynamic nature of Python, I doubt that's easy to do.
I'm not sure even os.listdir(), for example, can be relied on,
given that you can import modules from zip files, or if the
import hook is used, even from remote locations or, presumably
(though I haven't seen it done yet), from "thin air" where
the module is generated dynamically.

-Peter



More information about the Python-list mailing list