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

Alex Martelli aleaxit at yahoo.com
Mon Aug 6 07:45:16 CEST 2001


<fleet at teachout.org> wrote in message
news:mailman.997066209.23085.python-list at python.org...
>
> 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.

modobj = __import__(sys.argv[1])

imports the module named by sys.argv[1] and places a reference to
the resultin module object in variable modobj.

So, the loop:

> >for x in dir(os):

becomes:
    for x in dir(modobj):

and so on.


Alex






More information about the Python-list mailing list