how to determine for using c extension or not ?

Skip Montanaro skip.montanaro at gmail.com
Mon Aug 3 15:30:24 CEST 2015


id() tells you nothing about the nature of the function. Use the
inspect.isbuiltin():

    >>> import bisect
    >>> bisect.bisect
    <built-in function bisect>
    >>> import inspect
    >>> def foo(): pass
    ...
    >>> inspect.isbuiltin(foo)
    False
    >>> inspect.isbuiltin(bisect.bisect)
    True

It's perhaps a bit poorly named, but "builtin" functions are those not
written in Python. That is, those written in C or C++.

Skip


More information about the Python-list mailing list