harmful str(bytes)

Hallvard B Furuseth h.b.furuseth at usit.uio.no
Mon Oct 11 15:11:11 EDT 2010


Terry Reedy writes:
>On 10/8/2010 9:31 AM, Hallvard B Furuseth wrote:
>> That's not the point - the point is that for 2.* code which _uses_ str
>> vs unicode, the equivalent 3.* code uses str vs bytes.  Yet not the
>> same way - a 2.* 'str' will sometimes be 3.* bytes, sometime str.  So
>> upgraded old code will have to expect both str and bytes.
>
> If you want to interconvert code between 2.6/7 and 3.x, use unicode and
> bytes in the 2.x code. Bytes was added to 2.6/7 as a synonym for str
> explicitly and only for conversion purposes.

That's what I did, see article <hbf.20101008cg74 at bombur.uio.no>.
And that's exactly what broke as described, because bytes.__str__
have different meanings in 2.x and 3.x: the raw contents vs the repr.
So a library function which did %s output a different result.

-- 
Hallvard



More information about the Python-list mailing list