1
Vote

eval() function doesn't work as expected

description

The following simple code will raise exception:
f = lambda: x + 1
print eval(f.func_code, {'x': 2})
 
NameError: global name 'x' is not defined
 
while using python will successfully print the result.

comments