importing module through variable

Jaap Groot jaap.groot at zora.nl
Tue Jun 13 10:49:30 EDT 2000


You could do a:
exec "import %s" % var
exec "modvar=%s" % var

and refer to the module afterwards with modvar in your code!

with regards,

Jaap

André Dahlqvist <andre at beta.telenordia.se> wrote in message
news:8i5e9p$nm0$1 at zingo.tninet.se...
> Hi
>
> I have a variable which is assigned the name of a module. Is it possible
> to use this variable in an import statement? Someone told me I could use
> "exec("import %s" %var) and while this works I am not sure how I can
> access the module by it's name after that. Using something like
> var.modfunc() won't do it since 'var' is just a string containing the
> modules name.
>
> // André





More information about the Python-list mailing list