Scoping Issues

SherjilOzair sherjilozair at gmail.com
Thu May 24 21:23:18 EDT 2012


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 to see if python was the same as Go in this regard. Sorry, if I'm being rude, or anything. 



More information about the Python-list mailing list