what is a function object?

zakons at eccelerate.com zakons at eccelerate.com
Wed Nov 10 22:16:52 CET 1999


 Michael Hudson <mwh21 at cam.ac.uk> wrote:

> Then "re.sub('{{[^}]*}}',Replacer(n).replace,line)" does what I want
> (NB: I could have called the `replace' method `__call__' and then
> written `Replacer(n).replace' as `Replacer(n)'; that I didn't is a
> personal bias of mine and makes no difference to the point).
>

Cool example Michael. I definitely prefer the use of `__call__' in this
example because it would encapsulate the entire behavior a lot better. I
like the idea of instantiating an object with behavior determined by the
parameters passed to the constructor, and having that object implement
the function's logic through the saved state.

Thanks,
Stuart



Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list