Testing if an object is a function

Claus Tondering claus.tondering at gmail.com
Thu Oct 5 06:59:01 EDT 2006


If I want to test if an object, x, is an integer, I can call
isinstance(x, int).

But what do I do if I want to test if x is a function?

I can do this:

     if isinstance(x, type(lambda: None)): ...

But it does not seem very elegant to me.

Surely there is a simpler way to specify a type object that is the type
of a function.

--
Claus Tondering




More information about the Python-list mailing list