Callable assertion?

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Oct 6 06:41:49 EDT 2003


Gerrit Holl <gerrit at nl.linux.org> wrote in 
news:mailman.1065434008.19681.python-list at python.org:

> Is there a difference between callable(a) and hasattr(a, '__call__')?
> 

>>> class C: pass

>>> callable(C), hasattr(C, '__call__')
(True, False)

A few other strange objects in the system show the same behaviour 
(socket.socket for one), but new style classes and most builtin objects are 
well behaved (i.e. they have the __call__ attribute if they are callable).

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list