funcs vs vars in global namespace
David Rysdam
drysdam at ll.mit.edu
Tue Sep 14 14:25:04 EDT 2004
Alex Martelli wrote:
> 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
Ah, I see.
Your "which_dict_this_time" dictionary, how are you imagining that
working? I was just mapping function name strings to functions
({'logError':logError}), but (long story short) that isn't working how I
want. But shouldn't I be able to define the function right there in the
dictionary itself?
Perhaps this is getting too non-obvious, magical and unmaintainable, though.
More information about the Python-list
mailing list