Is there a way to change the closure of a python function?

Chris Angelico rosuav at gmail.com
Tue Sep 27 17:33:02 EDT 2016


On Wed, Sep 28, 2016 at 7:19 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> The value of the cell variable is writable from within the body of the
> closure function if declared nonlocal, but not otherwise, and not from
> without.  The latter may be what Peng meant by 'change' and the blogger by
> 'read-only'.
>

Not from entirely without, but it's possible for two functions to
share a cell. I don't know the mechanics of how nonlocal assignment
works, but ultimately, it's updating the cell that both closures see,
so it's going to affect the other function too.

ChrisA



More information about the Python-list mailing list