[Python-ideas] Explicit variable capture list

Michael Selik mike at selik.org
Wed Feb 17 18:35:33 EST 2016


> On Feb 16, 2016, at 4:07 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> 
> Since writing this, I realized that defining a custom class and using bound methods is a fourth option, which I also like. This binds the differentiating data to an instance, which is then bound to the function, rather than to the function directly.  A toy example:

Does this deserve a link to the closures == classes koan? I think so :-)

https://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html

Anywhere someone suggests a closure, a class can probably do the work. And vice-versa, though one will often be more elegant than the other for a particular circumstance.


More information about the Python-ideas mailing list