why this error?

Joshua Kugler jkugler at bigfoot.com
Sun Dec 16 16:18:11 EST 2007


python.jiang wrote:

> hello friends, the question had show bellow, any friend can tell me why.
> thanks.
>  
> list:
> def test():
>   exec "import sys"
>   a=range(15)
>   b=[13,3]
>   c=filter(lambda x: x not in b,a)
>   return c
> print test()
>  
> run result:
>   File "a.py", line 2
>     exec "import sys"
> SyntaxError: unqualified exec is not allowed in function 'test' it
> contains a nested function with free variables

I have no reason why you're getting the error, but there is no reason to try
to exec an import.  Just use

import sys

Hope that helps.

j




More information about the Python-list mailing list