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


Groups > comp.lang.python > #78383 > unrolled thread

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

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2014-09-26 10:10 -0600
Last post2014-09-26 10:10 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: any way to tell at runtime whether a callable is implemented in Python or C ? Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-26 10:10 -0600

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

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-09-26 10:10 -0600
SubjectRe: any way to tell at runtime whether a callable is implemented in Python or C ?
Message-ID<mailman.14398.1411747869.18130.python-list@python.org>
On Fri, Sep 26, 2014 at 6:12 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:
> 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.

Meanwhile, Python classes and objects with __call__ methods have no
__code__ attribute.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web