Callable assertion?

Terry Reedy tjreedy at udel.edu
Sun Oct 5 17:20:01 EDT 2003


"Lulu of the Lotus-Eaters" <mertz at gnosis.cx> wrote in message
news:mailman.1065381789.5393.python-list at python.org...
> "Terry Reedy" <tjreedy at udel.edu> wrote previously:
> |The acid test is to try calling it:
> |try: param()
> |except TypeError, msg: <do whatever>
>
> This is usually a bad idea though.

I disagree.  The OP previously got the iscallable() answer, with the
caveat that True may be a lie, and I posted in that context.  One
might still want to wrap the actual call in a try block.  It is the
same for reading files or making socket connections.  No matter what
pre-info one gathers, the acid test is to try to do it, and a careful
coder will prepare for possible failure.

>  Many, if not most, things you call  can either have side effects
and/or
> consume non-trivial resources (time, memory, especially).
> For example, you don't want to change state by making a call if you
know
> you are not ready for that state change until something else
happens.

Of course.  I assumed the OP already knows this.

> But you may want to know whether 'param' is callable before you
bother
> with the setup code.

Of course, but regardless of 'want', you cannot know for sure, as 1 or
2 others have said and shown (see Rodriguez' post).

Terry J. Reedy






More information about the Python-list mailing list