Re: Scoping Issues

2012-05-25 Thread Ethan Furman
Andrew Berg wrote: On 5/24/2012 8:59 PM, Dave Angel wrote: so I fixed that, and got inconsistent use of tabs and spaces in indentation because you mistakenly used tabs for indentation. Not to start another tabs-vs.-spaces discussion, but tabs are perfectly legal indentation in Python. Tha

Re: Scoping Issues

2012-05-25 Thread Jean-Michel Pichavant
Andrew Berg wrote: On 5/24/2012 8:59 PM, Dave Angel wrote: so I fixed that, and got inconsistent use of tabs and spaces in indentation because you mistakenly used tabs for indentation. Not to start another tabs-vs.-spaces discussion, Too late, the seeds of war have been planted

Re: Scoping Issues

2012-05-24 Thread Dave Angel
On 05/24/2012 10:27 PM, Andrew Berg wrote: > On 5/24/2012 8:59 PM, Dave Angel wrote: >> so I fixed that, and got >> inconsistent use of tabs and spaces in indentation >> >> because you mistakenly used tabs for indentation. > Not to start another tabs-vs.-spaces discussion, but tabs are perfect

Re: Scoping Issues

2012-05-24 Thread Andrew Berg
On 5/24/2012 8:59 PM, Dave Angel wrote: > so I fixed that, and got > inconsistent use of tabs and spaces in indentation > > because you mistakenly used tabs for indentation. Not to start another tabs-vs.-spaces discussion, but tabs are perfectly legal indentation in Python. That exception is

Re: Scoping Issues

2012-05-24 Thread Dave Angel
On 05/24/2012 09:23 PM, SherjilOzair wrote: > def adder(): > s = 0 > def a(x): > s += x > return sum > return a > > pos, neg = adder(), adder() > for i in range(10): > print pos(i), neg(-2*i) > > This should work, right? Why does it not? > Guess that dep

Re: Scoping Issues

2012-05-24 Thread Chris Rebert
On Thu, May 24, 2012 at 6:23 PM, SherjilOzair wrote: > def adder(): >        s = 0 >        def a(x): Add a "nonlocal s" declaration right here. See http://www.python.org/dev/peps/pep-3104/ >            s += x >            return sum >        return a > > pos, neg = adder(), adder() > for i in r

Re: Scoping Issues

2012-05-24 Thread Steven D'Aprano
On Thu, 24 May 2012 18:23:18 -0700, SherjilOzair wrote: > def adder(): > s = 0 > def a(x): > s += x > return sum > return a I think you mean "return s", not sum. > This should work, right? Why does it not? No, it shouldn't. When you have an assignment, suc

Re: Scoping Issues

2012-05-24 Thread MRAB
On 25/05/2012 02:23, SherjilOzair wrote: def adder(): s = 0 def a(x): s += x return sum return a pos, neg = adder(), adder() for i in range(10): print pos(i), neg(-2*i) This should work, right? Why does it not? Checkout slide no. 37 of a

Scoping Issues

2012-05-24 Thread SherjilOzair
def adder(): s = 0 def a(x): s += x return sum return a pos, neg = adder(), adder() for i in range(10): print pos(i), neg(-2*i) This should work, right? Why does it not? Checkout slide no. 37 of a Tour of Go to know inspiration. Just wanted