[Python-ideas] Explicit variable capture list

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Jan 20 23:59:52 EST 2016


My idea for handling this kind of thing is:

   for new x in things:
     funcs.append(lambda: dosomethingwith(x))

The 'new' modifier can be applied to any assignment target,
and conceptually has the effect of creating a new binding
instead of changing an existing binding.

There is a very simple way to implement this in CPython:
create a new cell each time instead of replacing the
contents of an existing cell.

-- 
Greg



More information about the Python-ideas mailing list