Re: Importing modules

Guido.van.Rossum@cwi.nl
Wed, 08 Feb 1995 20:13:11 +0100

> I would like to know if there is a way in which I could do the following :-
>
> x='fred'
> import x
>
> this should be the same as
>
> import fred

Use the exec statement:

x = 'fred'
exec "import " + x

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>