How to: get list of modules in a package

Peter L Hansen peter at
Tue Oct 12 17:05:23 CEST 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.


More information about the Python-list mailing list