Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78377

Re: any way to tell at runtime whether a callable is implemented in Python or C ?

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: any way to tell at runtime whether a callable is implemented in Python or C ?
Date 2014-09-26 14:12 +0200
References <m035kl$54v$1@ger.gmane.org> <CAPTjJmpg1LkHk4FDSQX30Tusdw_9=+iVUDXyntLN1TVrbX4U7g@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14393.1411733564.18130.python-list@python.org> (permalink)

Show all headers | View raw


Chris Angelico schrieb am 26.09.2014 um 10:42:
> On Fri, Sep 26, 2014 at 5:47 PM, Wolfgang Maier wrote:
>> is there any reliable and inexpensive way to inspect a callable from running
>> Python code to learn whether it is implemented in Python or C before calling
>> into it ?
> 
> I'm not sure you can say for absolute certain, but the presence of a
> __code__ attribute is strongly suggestive that there's Python code
> behind the function. That might be good enough for your purposes.

Cython implemented native functions have a "__code__" attribute, too. Their
current "__code__.co_code" attribute is empty (no bytecode), but I wouldn't
rely on that for all times either.

Stefan

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: any way to tell at runtime whether a callable is implemented in Python or C ? Stefan Behnel <stefan_ml@behnel.de> - 2014-09-26 14:12 +0200

csiph-web