pkgutil may be helpful.
Also see this SO question. This is a form of sample code.
kaizer.se
import pkgutil
import email
package = email
for importer, modname, ispkg in pkgutil.iter_modules(package.__path__):
print "Found submodule %s (is a package: %s)" % (modname, ispkg)
~ unutbu
import pkgutil
for importer, modname, ispkg in pkgutil.walk_packages(path=None, onerror=lambda x: None):
print(modname)
source
share