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

Tom Robinson tom at alkali.spamfree.org
Sun Aug 5 20:50:53 CEST 2001


On Sat, 04 Aug 2001 19:37:26 GMT, engsol at teleport.com wrote:

>"""
>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.
>"""

<snip>

Here's a hack to show the __doc__ for everything in a module:

import os

for x in dir(os):
    try:
        print "%s\n%s\n%s\n" % (x, '-'*35, os.__dict__[x].__doc__)
    except AttributeError:
        print "*** no __doc__ for os.%s\n" % (x)

-- 
tom at alkali.spamfree.org
remove 'spamfree.' to respond



More information about the Python-list mailing list