Re: A problem with exec statement

2006-04-15 Thread Peter Otten
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

Re: A problem with exec statement

2006-04-14 Thread TPJ
> > 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 =

Re: A problem with exec statement

2006-04-14 Thread TPJ
> 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 ..."

Re: A problem with exec statement

2006-04-14 Thread Steve Holden
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

Re: A problem with exec statement

2006-04-14 Thread Peter Otten
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

A problem with exec statement

2006-04-13 Thread TPJ
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(