[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Closures and Partial Function Application
From:       Terry Reedy <tjreedy () udel ! edu>
Date:       2011-08-31 22:21:06
Message-ID: j3mc5u$pt7$1 () dough ! gmane ! org
[Download RAW message or body]

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

-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic