F
Fabio Zadrozny
Hi All,
Anyone knows why the code below gives an error?
global_vars = {}
local_vars = {'ar':["foo", "bar"], 'y':"bar"}
print eval('all((x == y for x in ar))', global_vars, local_vars)
Error:
Traceback (most recent call last):
File "C:\temp\work\test\src\a.py", line 3, in <module>
print eval('all((x == y for x in ar))', global_vars, local_vars)
File "<string>", line 1, in <module>
File "<string>", line 1, in <genexpr>
NameError: global name 'y' is not defined
Note that if a list is used instead of a generator it works...
Thanks,
Fabio
Anyone knows why the code below gives an error?
global_vars = {}
local_vars = {'ar':["foo", "bar"], 'y':"bar"}
print eval('all((x == y for x in ar))', global_vars, local_vars)
Error:
Traceback (most recent call last):
File "C:\temp\work\test\src\a.py", line 3, in <module>
print eval('all((x == y for x in ar))', global_vars, local_vars)
File "<string>", line 1, in <module>
File "<string>", line 1, in <genexpr>
NameError: global name 'y' is not defined
Note that if a list is used instead of a generator it works...
Thanks,
Fabio