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


Groups > comp.lang.python > #94952

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

From Terry Reedy <tjreedy@udel.edu>
Subject Re: how to determine for using c extension or not ?
Date 2015-08-03 14:11 -0400
References <55BF67CB.5030604@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1198.1438625504.3674.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

Re: how to determine for using c extension or not ? Terry Reedy <tjreedy@udel.edu> - 2015-08-03 14:11 -0400

csiph-web