funcs vs vars in global namespace
Alex Martelli
aleaxit at yahoo.com
Tue Sep 14 14:17:04 EDT 2004
David Rysdam <drysdam at ll.mit.edu> wrote:
...
> OK, dumb question #1:
>
> Why do this:
>
> sub_module = __import__(which_module_this_time)
> vars(sub_module).update(which_dict_this_time)
>
> When I could just do this:
>
> __import__(which_module_this_time, which_dict_this_time)
>
> ?
You can do whatever you wish, but what makes you think these constructs
have similar effects? Quoting from Python's online docs on __import__,
"""
the standard implementation does not use its locals argument at all,
and uses its globals only to determine the package context of the
import statement
"""
In short, the standard implementation of __import__ does NOT alter in
any way the dict of the module it imports.
Alex
More information about the Python-list
mailing list