TPJ wrote:
>> (...) Even allowing for the
>> difficulties you've already experienced, it's nearly always better in
>> practical cases to use assignment to the keys of a dictionary. Then no
>> exec is required, and you have direct control over your own namespace.
>
> Well... Is this a sugestion, t
>
> So when you exec 'a = "B"' in globals(), locals() you might think you
> were changing the local namespace. In fact you are changing a copy of
> the local namespace:
>
Well, that explains much, but not all that I want to be explained. Why?
Because now I understand, that by invoking
exec "a =
> Use the exec statement without the in-clause to get the desired effect:
>
> >>> def f():
> ... a = "a"
> ... exec "a = 'B'"
> ... print a
> ...
> >>> f()
> B
>
Well... I *do* realize that. But this is *not* my problem. I have a
function with another nested one. If I used "exec ..."
TPJ wrote:
> I have the following code:
>
> ---
> def f():
>
> def g():
> a = 'a' # marked line 1
> exec 'a = "b"' in globals(), locals()
> print "g: a =", a
>
> a = 'A' # marked line 2
> exec 'a = "B"' in globals(), loc
TPJ wrote:
> I have the following code:
>
> ---
> def f():
>
> def g():
> a = 'a' # marked line 1
> exec 'a = "b"' in globals(), locals()
> print "g: a =", a
>
> a = 'A' # marked line 2
> exec 'a = "B"' in globals(), lo
I have the following code:
---
def f():
def g():
a = 'a' # marked line 1
exec 'a = "b"' in globals(), locals()
print "g: a =", a
a = 'A' # marked line 2
exec 'a = "B"' in globals(), locals()
print "f: a =", a
g()
f(