Don't understand syntax error: unqualified exec is not allowed ..
stef.mientki at gmail.com
Tue Oct 21 23:45:53 CEST 2008
Terry Reedy wrote:
> Stef Mientki wrote:
>>>> import sys
>>>> p_locals = sys._getframe(1).f_locals
>>> Which locals does this get you? __init__'s? (locals()?)
>> AFAIK locals() == sys._getframe(0).f_locals
> Then it is not clear to me which locals your are getting.
The locals of the code block where the instance of this class is created.
>>>> p_globals = sys._getframe(1).f_globals
>>> Isn't this just the same as globals()?
>> AFAIK, again one level up
>>>> try :
>>>> exec ( code, p_globals, p_locals )
>>> This is 3.0 exec function syntax.
>> weird, I use it in 2.5 and if I remember well it already worked in 2.4.
>> but exchanging the function with the statement yields exactly the
>> same results
> 2.5 manual says
> "6.14 The exec statement
> exec_stmt ::= "exec" or_expr ["in" expression ["," expression]]
> This statement supports dynamic execution of Python code. The first
> expression should evaluate to either a string, an open file object, or
> a code object."
> Your expression evaluates to a tuple (triple), which is not documented.
No I think it's indeed handled as function call.
I now that, because the globals (and sometimes ??? the locals) of the
codeblock where the class is initiated is changed.
> From the error message, I wondoer if p_globals, p_locals is ignored. Try
> exec code in p_globals, p_locals
Yes I've already done that,
and this yields exactly the same results.
So I guess that the exec-function is already there and doesn't differ
from the exec-statement.
And indeed nothing to find about the exec-function in the 2.5
But on the other hand,
I'm a very practical guy,
and my code seems to work quit correct now,
so I'm satisfied for the moment ;-)
More information about the Python-list