Loaded module list and attributes

Steve Holden sholden at holdenweb.com
Mon Jul 30 10:07:34 EDT 2001


"Dale Strickland-Clark" <dale at riverhall.NOSPAMco.uk> wrote in message
news:o2mamt4qtis8r77maqnsmjg7h193aa80t4 at 4ax.com...
> How do I itterate through all the loaded modules and find the name of the
module and a value of a
> local attribute (__version__ in this case)?
>
> I'm writing a small debugging routine and Python internals are still a bit
of a black box to me.
>
> Thanks.

Probably you want to iterate over sys.modules -- one way to do this is:

    for k in sys.modules.keys():
        module = sys.modules[k]
        print module.__version__

However you will need to ensure that a particular module HAS a __version__
attribute before referencing it, or trap the AttributeError exception which
will result when it doesn't.

regards
 STeve
--
http://www.holdenweb.com/








More information about the Python-list mailing list