[Python-Dev] thoughts on the bytes/string discussion

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Jun 25 03:28:14 CEST 2010


Terry Reedy wrote:
> On 6/24/2010 1:38 PM, Bill Janssen wrote:
> 
>> We have separate types for int,
>> float, Decimal, etc.  But they're all numbers, and they all
>> cross-operate.
> 
> No they do not. Decimal only mixes properly with ints, but not with 
> anything else

I think there are also some important differences between
numbers and strings concerning how they interact with C code.

In C there are really only two choices for representing a
Python number in a way that C code can directly operate on --
long or double -- and there is a set of functions for coercing a
Python object into one of these that C code almost universally
uses. So a new number type only has to implement the appropriate
conversion methods to be usable by all of that C code.

On the other hand, the existing C code that operates on Python
strings often assumes that it has a particular internal
representation. A new abstract string-access API would have to
be devised, and all existing C code updated to use it. Also,
this new API would not be as easy to use as the number API,
because it would involve asking for the data in some specified
encoding, which would require memory allocation and management.

-- 
Greg


More information about the Python-Dev mailing list