Re: Function closure inconsistency

2010-07-23 Thread Terry Reedy
On 7/23/2010 2:30 PM, SeanMon wrote: I was playing around with Python functions returning functions and the scope rules for variables, and encountered this weird behavior that I can't figure out. Why does f1() leave x unbound, but f2() does not? def f1(): x = 0 def g(): In 3.x, add

Re: Function closure inconsistency

2010-07-23 Thread Dave Angel
SeanMon wrote: I was playing around with Python functions returning functions and the scope rules for variables, and encountered this weird behavior that I can't figure out. Why does f1() leave x unbound, but f2() does not? def f1(): x = 0 def g(): x += 1 return x re

Re: Function closure inconsistency

2010-07-23 Thread Benjamin Kaplan
On Fri, Jul 23, 2010 at 11:30 AM, SeanMon wrote: > > I was playing around with Python functions returning functions and the > scope rules for variables, and encountered this weird behavior that I > can't figure out. > > Why does f1() leave x unbound, but f2() does not? > > def f1(): >    x = 0 >  

Function closure inconsistency

2010-07-23 Thread SeanMon
I was playing around with Python functions returning functions and the scope rules for variables, and encountered this weird behavior that I can't figure out. Why does f1() leave x unbound, but f2() does not? def f1(): x = 0 def g(): x += 1 return x return g1 def f2()