how to import from variable source
Joonas Paalasmaa
joonas at olen.to
Sun Apr 15 16:19:50 EDT 2001
Rob Brown-Bayliss wrote:
>
> Hello
>
> I am building a shell type app that imports modules depending on the
> users actions.
>
> I do not want to have the import routines hard coded, rather I would
> like to import from a variable like so:
>
> module = 'mymod'
> import module
>
> Only, as I found out I get an error stating that there is not module
> called module.
>
> Is this possible in python? Is there a better way perhapse?
>
> Thanks,
You can use exec statement.
module = 'mymod'
exec "import "+module
--
#!/usr/bin/python
for y in 0,1:
for x in range(y,32,2):print "J ojoonoansa sP at aoalleans.mtaoa "[x],
print
More information about the Python-list
mailing list