ARGV and import ?
ykingma at accessforall.nl
Tue Oct 9 21:48:38 CEST 2001
Steve Holden wrote:
> "J" <geek_girl at mailcity.com> wrote ...
> > Hi all,
> > This is my first post to this group & I am also fairly new to python,
> > so please forgive me if this isn't the brightest question or the
> > appropriate venue.
> > I would like to do the following:
> > import a module based on what is typed on the command line.
> > I thought this would work:
> > import sys
> > recipes = sys.argv
> > import recipes
> > But, I get this error:
> > >> ImportError: No module named recipes
> > Is there any way to pass the module name to import through an argv?
> but also be aware that's a potentially dangerous program in someone else's
> hands ... they can import any module they like, and the module is EXECUTED
> the first time it's imported.
One can do:
recipes = __import__(sys.argv)
to have recipes refer to a module.
email at xs4all.nl
More information about the Python-list