how to find out if an object is a class?
Stefan Behnel
stefan_ml at behnel.de
Fri Aug 8 10:38:14 EDT 2008
Miles wrote:
> 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)
Congratulations, you found the trivial case.
Stefan
More information about the Python-list
mailing list