modifying locals
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Fri Oct 31 03:22:45 EDT 2008
On Thu, 30 Oct 2008 16:19:11 -0700, John [H2O] wrote:
> Steven D'Aprano-7 wrote:
>>
>> What you are actually trying to do is unclear to me. Perhaps you could
>> try explaining better with a more concrete example?
>>
> Actually, maybe a LACK of an example would make it simpler. What I'm
> after is a function, to which I can pass a dictionary defined from
> locals(), then in the function I would modify some of the variables from
> the dictionary. But I want the modifications to be 'seen' by the method
> that called the function without passing them back via return.
Why do you want that? That is typically something you don't want,
because it can make the program hard to understand very easily. Python
has no dynamic scoping and if you "hack" this into you program the
function call has very unexpected and surprising side effects.
So I ask for the use case too. What problem are you trying to solve?
There might be a better way than executing strings as code and trying to
inject names into the callers namespace.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list