[Tutor] Listing imported modules

Tim Johnson tim at johnsons-web.com
Sat Sep 13 19:55:19 CEST 2008

On Friday 12 September 2008, you wrote:
> On Fri, Sep 12, 2008 at 8:42 PM, Tim Johnson <tim at johnsons-web.com> wrote:
> > If I execute the following code:
> >
> > imported = sys.modules.keys()
> >
> > print imported
> >
> > Do I indeed get a list of _all_ modules imported by this module?
> You get a list of all modules that have been imported at any time by
> the running program, not necessarily just in the current module.
> > If so, then could anyone offer suggestion on how to "parse" the
> >
> > non-standard modules from this list. I.E. modules _not_ included in
> >
> > the standard python distribution.
> sys.modules is a dict mapping names to the actual modules. Most
> modules have a __file__ attribute that is the path to the file
> containing the module. Perhaps you could filter out the modules that
> are in the standard library path and see what is left.
  Thanks Kent. And there is also the Global Module Index at 
  http://docs.python.org/modindex.html. I could convert that to a data
  structure to use as the control.

More information about the Tutor mailing list