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


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

Re: how to determine for using c extension or not ?

Started byTerry Reedy <tjreedy@udel.edu>
First post2015-08-03 14:11 -0400
Last post2015-08-03 14:11 -0400
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: how to determine for using c extension or not ? Terry Reedy <tjreedy@udel.edu> - 2015-08-03 14:11 -0400

#94952 — Re: how to determine for using c extension or not ?

FromTerry Reedy <tjreedy@udel.edu>
Date2015-08-03 14:11 -0400
SubjectRe: how to determine for using c extension or not ?
Message-ID<mailman.1198.1438625504.3674.python-list@python.org>
On 8/3/2015 9:08 AM, umedoblock wrote:

Posting three times under two different names is not polite.  Please to 
not  repeat.

> I use bisect module.
> bisect module developer give us c extension as _bisect.

We call that a C accelerator.

> If Python3.3 use _bisect, _bisect override his functions in bisect.py.

An accelerator may override either some or all functions.
In this case, Lib/bisect.py ends with

try:
     from _bisect import *
except ImportError:
     pass

For CPython, I expect that all 4 similar functions (and two synonyms) 
get replaced.

> now, I use id() function to determine for using c extension or not.

You should not care.  If you think there is an undocumented difference 
in behavior, ask here if it is a bug.

I expect that that test/test_bisect.py runs the same tests on both 
versions.  We have a test helper function for such situations.  It 
blocks the import of the accelerator so that the Python version can be 
tested.

>>>> import bisect
>>>> id(bisect.bisect)
> 139679893708880
>>>> import _bisect
>>>> id(_bisect.bisect)
> 139679893708880
>
> they return 139679893708880 as id.
> so i believe that i use c extension.

The bisect and _bisect modules are different objects.  Since they and 
their global namespace exist simultaneously, then yes, the above says 
that both have the name 'bisect' bound to the C-coded built-in version.

-- 
Terry Jan Reedy

[toc] | [standalone]


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


csiph-web