Closures and Partial Function Application

Terry Reedy tjreedy at udel.edu
Thu Sep 1 00:21:06 CEST 2011


On 8/31/2011 12:45 PM, Travis Parks wrote:
> I was a little disappointed the other day when I realized that
> closures were read-only.

'Were', in 2.x. The standard 2.x workaround for a single nonlocal is to 
wrap it in a list.

def f():
     i = [0]
     def g(): i[0] += 1
     for j in range(5): g()
     print(i)

f()
# 5

-- 
Terry Jan Reedy




More information about the Python-list mailing list