Re: [Tutor] Odd behavior with eval, list comps, and name lookup

2011-02-18 Thread Peter Otten
John wrote: > I noticed some odd behavior relating to eval(). First, a baseline case for > behavior: > def test(): > ... x = 5 > ... return [a for a in range(10) if a == x] > ... test() > [5] > > So far so good. Now let's try eval: > c = compile('[a for a in range(10) if a == x]'

[Tutor] Odd behavior with eval, list comps, and name lookup

2011-02-18 Thread John
I noticed some odd behavior relating to eval(). First, a baseline case for behavior: >>> def test(): ... x = 5 ... return [a for a in range(10) if a == x] ... >>> test() [5] So far so good. Now let's try eval: >>> c = compile('[a for a in range(10) if a == x]', '', 'single') >>> eval(c, globals(