import question

Alex Martelli aleaxit at yahoo.com
Fri Nov 3 07:48:37 EST 2000


<kopfarzt at my-deja.com> wrote in message news:8tu5th$qj$1 at nnrp1.deja.com...
> Hi,
>
> how can I dynamically import modules in function
> a() , and then call them by name in function b()
> instead of using the module object?
>
> what I want to do is something like this:
>
> def a():
>   module = __import__ ('foo')
>
> def b():
>   x = eval ('foo.bar ()')

For example:

def a():
    exec 'import foo' in globals()

def b():
    x = eval('foo.bar()')


Alex






More information about the Python-list mailing list