Possible to import a module whose name is contained in a variable?

Hye-Shik Chang hyeshik at gmail.com
Mon Mar 7 00:47:51 EST 2005


On 6 Mar 2005 21:34:08 -0800, Steven Reddie <smr at essemer.com.au> wrote:
> Hi,
> 
> I want to do something like the following, which doesn't work:
> 
>     modulename = 'module'
>     import modulename
> 
> The error is that there is no module named 'modulename'.  Is there a
> way to get that variable expanded?
> 

modulename = 'module'
module = __import__(modulename)


Hye-Shik



More information about the Python-list mailing list