[Tutor] Passing a variable to 'import'

alan.gauld@bt.com alan.gauld@bt.com
Thu, 20 Dec 2001 10:49:53 -0000


> > >>moduleName="someModule"
> > 
> > >>def import_module(someModule):
> >         import someModule
> 
> Sounds like a job for my once-beloved "exec" statement. :)

Rob, this time I agree with you :-)

I think there may be other ways to do this using some of 
the internals of Python but in this case exec does seem 
the best option.

Alan G.