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

fleet at teachout.org fleet at teachout.org
Mon Aug 6 04:49:41 CEST 2001


I think I'm hung up on the substitution thing again.  If I wanted to name this 'show.py' and
be able to use 'python show.py math' on the command line - how do I get "import sys.argv[1]"
to work.  (and I would already have imported 'sys.')  I tried 'eval()' without success - kept
getting "invalid syntax" although the proper string was shown.

					- fleet -

>   From: Tom Robinson <tom at alkali.spamfree.org>
>Subject: Re: NEWBIE TIP: Displaying the contents of an imported module...from ENGSOL
>
>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