strange SyntaxError

Terry Reedy tjreedy at udel.edu
Fri Feb 25 13:26:58 EST 2005


"Attila Szabo" <trial at ugyvitelszolgaltato.hu> wrote in message 
news:20050225133355.GI20239 at csola.ugyvitelszolgaltato.hu...
> Hi,
>
> I wrote this sample piece of code:
>
> def main():
>        lambda x: 'ABC%s' % str(x)
>        for k in range(2): exec('print %s' % k)
>
> main()
>
> With the lambda line, I get this:
> SyntaxError: unqualified exec is not allowed in function 'main'
> it contains a nested function with free variables

The lambda expression is the nested function, the free variable is 'str'.
Since this general situation *could* be a problem, as Scott explained,
the compiler quits, since it cannot do the analysis needed to determine
whether the specific situation *is* a problem.

Terry J. Reedy








More information about the Python-list mailing list