TheSaint a écrit :
On 17:47, giovedì 12 giugno 2008 Bruno Desthuilliers wrote:
For multiple functions, use classes.
Well... Closures are poor men's objects, or so they say (or is that the
other way round ?-).
Well, I'd like to know what could be the reason to design a single-call class
instead of a similar function.
Convenience. FWIW, in Python, functions are objects, and when you use a
closure to maintain state, you in fact already use the function's class
features. Sometimes, it's just simpler and more straightforward to use a
custom callable object than closures. Two common examples are function
decorators taking arguments (which require "two levels" closures if you
want to define them as functions, something that the instanciation/call
scheme of a callable class handles naturally) and partial application.
--
http://mail.python.org/mailman/listinfo/python-list