Home

skip@pobox.com wrote:

> In this particular case it was clearly unnecessary and just obfuscated
> the code. I'm wondering, are there some general cases where __call__
> methods of a user-defined class are simply indispensable?

I don't know that you couldn't live without __call__, but it would make
some code harder to write and understand. The time you need __call__ is
when you need an object which is callable and which also has methods. e.g.
look at xmlrpclib:

server = ServerProxy('http://some.server.com/path')

server.method(x=5) retrieves the url http://some.server.com/path/method?x=5
server.method.submethod(x=5) retrieves the url
http://some.server.com/path/method/submethod?x=5


There is no need here to distinguish between a callable object and an
object used for traversal. I think without __call__, code to access web
servers would be less clean.

previous
next

Re: csv module
How to say $a=$b->{"A"} ||={} in Python?
Re: I could use some help making this Python code run faster using only Python code.
Re: using inspect on pygtk
Re: checking if a number is zero within machine precision
Fundacja Avalon
Nasze Dzieci
Fundacja Hobbit
Niechciane i Zapomniane
Dzieci Niczyje