how to find out if an object is a class?

Miles semanticist at gmail.com
Fri Aug 8 04:51:24 EDT 2008


On Fri, Aug 8, 2008 at 2:31 AM, Stefan Behnel wrote:
> I recently had the reverse case that a (stupidly implemented) extension module
> required a callback function and I wanted to pass a function wrapped in a
> wrapper object. That failed, because it specifically checked for the argument
> being a function, not just a callable object. I had to pull quite a number of
> tricks to reimplement the wrapper class as a function (thank god, it's Python!).

You really only needed one trick:

def functionize(callable):
    return lambda *args, **kwargs: callable(*args, **kwargs)

:)

-Miles



More information about the Python-list mailing list