NEWBIE TIP: Displaying the contents of an imported module...from ENGSOL

engsol at teleport.com engsol at teleport.com
Sat Aug 4 15:37:26 EDT 2001


"""
I'm brand new to Python, and while reading the books,
I tend to bread-board stuff just to see how it works.
I figure it's better to share....
If it's of use to other newbies, great.
If it's in error, please post a correction.
"""

#----FILE: show_mod.py

""" Sometimes you'd like to see some details
of a module you've imported. Here's one way
to do so.
"""

import os  # Or whatever module you'd like

env_list = os.environ
key_list = os.environ.keys()
dir_list = dir(os)

for keys in key_list:
    print "%-24s = %s" % (keys, env_list[keys])

# And to see even more:

for keys in dir_list:
    print "%-24s = %s" % (keys, eval("os." + keys))

# END: show_mod.py -------------------------------------------------------

""" PROGRAM RESULTS:

USERPROFILE              = C:\WINNT\Profiles\Administrator
MSDEVDIR                 = C:\Program Files\DevStudio\SharedIDE
OS                       = Windows_NT
OS2LIBPATH               = C:\WINNT\system32\os2\dll;
HOMEPATH                 = \
PROCESSOR_LEVEL          = 4
NUMBER_OF_PROCESSORS     = 1
PROCESSOR_ARCHITECTURE   = x86
SYSTEMDRIVE              = C:
PATHEXT                  = .COM;.EXE;.BAT;.CMD

<the rest snipped>

"""



More information about the Python-list mailing list