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, that

A problem with exec statement

2006-04-14 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()

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(), locals()   print 

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(), locals() print f:

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 snip Well... I *do* realize that. But this is *not* my problem. I have a function with another nested one. If I used exec ... instead of exec

Re: A problem with exec statement

2006-04-14 Thread TPJ
- by using a dictionary. And perhaps I will. But I still want to know, how the exec statement works. * * * My problem is more complicated, that the presented example. In general, my problem is: how to create a local variable by executing the Python code, that isn't known at the moment of writing