python: list modules within the package

Posted by ak on Stack Overflow See other posts from Stack Overflow or by ak
Published on 2010-03-29T08:29:38Z Indexed on 2010/03/29 8:33 UTC
Read the original article Hit count: 283

Filed under:
|
|
|

I have a package with a few modules, each module has a class (or a few classes) defined within it. I need to get the list of all modules within the package. Is there an API for this in python?

Here is the file structure:

\pkg\
\pkg\__init__.py
\pkg\module1.py -> defines Class1
\pkg\module2.py -> defines Class2
\pkg\module3.py -> defines Class3 and Class31

from within module1 I need to get the list of modules within pkg, and then import all the classes defined in these modules

Thanks ak

© Stack Overflow or respective owner

Related posts about python

Related posts about modules