[Tutor] Passing a variable to 'import'

Mark Rowe mark21rowe@yahoo.com
Thu, 20 Dec 2001 19:11:34 +1300


Hi,

Have a read up on the __import__ function in the Python documentation.

Mark Rowe


Chris Keelan wrote:

>I have a piece of code like so:
>
>moduleName="someModule"
>
>def import_module(someModule):
>	import someModule
>
>Of course that gives me the following output:
>
>Traceback (most recent call last):
>  File "<stdin>", line 1, in import_module
>ImportError: No module named moduleName
>
>So how do I, for example, grab a module name from sys.argv and then pass it 
>to the import command as a variable?
>
>- Chris
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com