funcs vs vars in global namespace
David Rysdam
drysdam at ll.mit.edu
Tue Sep 14 11:02:28 EDT 2004
Alex Martelli wrote:
> David Rysdam <drysdam at ll.mit.edu> wrote:
> ...
>>What I want to do is be able to run multiple scripts that use the same
>>global variable and function names but be able to have my master script
>>define those variables and functions programmatically. Can I do that
>>with the rexec sandbox stuff? Or is rexec more about keeping the
>>exec()'d code from doing things than specifying precisely what it can do?
>
>
> rexec has been removed because it did not offer the security it
> purported to offer (it was about keeping code from doing bad things, but
> it reallly didn't), sigh.
>
> You can do what you want for example by setting the values you want in
> the module object of the function you're calling -- that module object's
> dictionary is the function's global namespace. Say:
>
> sub_module = __import__(which_one_this_time)
> vars(sub_module).update(which_dict_this_time)
> print sub_module.the_function(23)
>
> There are other ways, but few are as direct as this one.
>
>
> Alex
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!
More information about the Python-list
mailing list