getting modules optionally

Steve Holden sholden at holdenweb.com
Wed Nov 21 08:52:35 EST 2001


"Giorgi Lekishvili" <gleki at gol.ge> wrote in message
news:3BFC2647.D9692B49 at gol.ge...
> Dear all!
>
> I apologize for this nebye-like question.
>
> Suppose, we have a package with one __init__.py file, while the rest are
> other modules (let's call them active modules), which do the essential
> stuff.
>
> Apparently, I need to start like this:
>
>
>      from MyPackage import *
>
> I need to import only one active module. This can be done by hardcoding:
>
>      from MyPackage.ThisModule import *
>
> What I can not do is to import the module, if I have its name as string.
>
>      modname='ThisModule'
>
> Of course, the code below doesn't work:
>
>      from MyPackage.modname import *
>
> The question: is there something like eval function, which could
> transfer the string as the real module name? In other words, how have I
> to treat the modname to make this code running?
>
>      from MyPackage.modname import *
>
Take a look at the built-in __import__() function.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list