problem with imort

Hans Nowak wurmy at earthlink.net
Sun Aug 25 22:08:23 EDT 2002


polux wrote:
> I wrote :
> 
> module=math
>  >>> import module
> Traceback (most recent call last):
>   File "<pyshell#8>", line 1, in ?
>     import module
> ImportError: No module named module
> 
> 
> How to do to give the function import a variable ?
> 

Use the __import__ function:

 >>> foo = "math"
 >>> math = __import__(foo)
 >>> math
<module 'math' (built-in)>

HTH,

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html




More information about the Python-list mailing list