Callable assertion?

Roy Smith roy at panix.com
Sun Oct 5 18:35:40 EDT 2003


"Terry Reedy" <tjreedy at udel.edu> wrote:
> 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.

There's a big difference between verifying that a passed parameter has 
the properties it's supposed to have and trying to figure out if you can 
read a file or open a socket.

The former catches a programming error.  If I meant to pass fred and I 
pass fred() by mistake, the problem is going to be there every time I 
run the program until I fix the code.

The latter catches problems caused by external events.  Files can appear 
and disapper, or have their permissions change, at any time, and all 
this is beyond the control (and knowledge) of my program.  For things 
like that, then yes, I agree that the way to find out if you can do 
something is to try it and see what happens.




More information about the Python-list mailing list