What are python closures realy like?

Michele Simionato michele.simionato at gmail.com
Wed Dec 6 11:39:26 EST 2006


Paul Boddie wrote:
> I'm not pointing the finger at you here, Karl, since you seem to be
> experimenting with closures, but why are they suddenly so fashionable?
> Haven't the features supporting them existed in Python for a few
> versions now? Don't people want to write classes any more?
>
> Intrigued,
>
> Paul

I believe decorators are in large part responsible for that. A callable
object does not work
as a method unless you define a custom __get__, so in decorator
programming it is
often easier to use a closure. OTOH closures a not optimal if you want
persistency
(you cannot pickle a closure) so in that case I use a callable object
instead.

       Michele Simionato




More information about the Python-list mailing list