funcs vs vars in global namespace

David Rysdam drysdam at ll.mit.edu
Tue Sep 14 13:40:55 EDT 2004


Alex Martelli wrote:
> David Rysdam <drysdam at ll.mit.edu> wrote:
>    ...
> 
>>>sub_module = __import__(which_one_this_time)
>>>vars(sub_module).update(which_dict_this_time)
>>>print sub_module.the_function(23)
> 
>    ...
> 
>>Oh wow, of course!  I can set properties on the modules themselves.  I'm
>>going to have to rethink what I'm doing and mess with that a bit, I'm
>>sure I'll have questions and problems later.  Thanks!
> 
> 
> You're welcome!  Yes, since your modules are not being used for other
> purposes except running the scriptlets you're controlling, changing
> those modules' global variables should be safe enough in your case.
> 
> 
> Alex

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)

?



More information about the Python-list mailing list