Listing modules from all installed packages
cclauss at bluewin.ch
cclauss at bluewin.ch
Sun Jun 9 08:51:36 EDT 2013
Adding : python -c 'help("modules") to the other two suggestions:
#!/usr/bin/env python
import commands, pkgutil, re, sys
print('sys.modules.items()...')
print('\n'.join(sorted([re.findall("from '(.*)'",str(v))[0] for k,v in sys.modules.items() if str(v).find('from')>-1])))
print('\npkgutil.iter_modules()...')
toplevel_packages = ['%s\\%s'%(ml.path,name)for ml,name,ispkg in sorted(pkgutil.iter_modules()) if ispkg]
print '\n'.join(toplevel_packages)
theCommand = "python -c 'help(\"modules\")'"
print('\n{} # this may take a few seconds...'.format(theCommand))
print(commands.getstatusoutput(theCommand)[1]) # help() only works in the python interpreter...
More information about the Python-list
mailing list