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
and must be change to bellow, then OK:
b=None
def testFilter(x):
global b
return x not in b
def test():
exec "import sys"
global b
a=range(15)
b=[13,3]
c=filter(testFilter,a)
return c
print test()
last run result is:
[0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14]
any friend can tell me why?
thanks alot very much!!
--
http://mail.python.org/mailman/listinfo/python-list