Callable assertion?

Roy Smith roy at panix.com
Sun Oct 5 08:55:45 EDT 2003


I've got a function which gets passed a call-back function as a 
parameter.  I want to check to make sure the thing passed in is indeed 
callable.  Is:

assert '__call__' in dir (param)

the right thing to do, or is there something cleaner?  Will that work 
for all callable values of param, regardless if it's a static function, 
class method, built-in, etc?

I'm running 2.3.1.  Backward compatability isn't particularly an issue 
for me, but I guess it would be nice to know how far back in time this 
works.




More information about the Python-list mailing list