Why doesn't eval of generator expression work with locals?

James Mills prologic at shortcircuit.net.au
Tue Jan 27 18:51:37 EST 2009


On Wed, Jan 28, 2009 at 9:31 AM, Fabio Zadrozny <fabiofz at gmail.com> wrote:
> 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)

y is undefined in your generator expression.

Why are you using eval ?

cheers
James



More information about the Python-list mailing list