Callable assertion?
Terry Reedy
tjreedy at udel.edu
Sun Oct 5 21:49:48 EDT 2003
"Roy Smith" <roy at panix.com> wrote in message
news:roy-93EAD2.18123305102003 at reader2.panix.com...
> I hear what you're saying,
?
> but it's still nice to be able to check ahead of time.
Of course; I never said otherwise. Nor, that I remember, did I say to
not use callable(). I merely stated the reality that the ultimate
test for this particular property, in Python, is an actual call.
If I were writing the callback recipient purely for my own use, I
might decide to make no check and deal with the traceback should I
slip up and pass a non-callable. If I were writing a library routine
for the whole world to use, I might both test with callable() *and*
wrap the callback call.
A similar frequently asked question is "How can I check, before using
it, that a passed parameter is a number?" Seems simple, but depending
on the
definition of 'number', it may not be easily checkable in Python.
(See archives for more.)
Terry J. Reedy
More information about the Python-list
mailing list