harmful str(bytes)

Stefan Behnel stefan_ml at behnel.de
Mon Oct 11 16:23:42 EDT 2010


Hallvard B Furuseth, 11.10.2010 21:50:
> Antoine Pitrou writes:
>> 2) some unicode objects didn't have a succesful str()
>>
>> Python 3 fixes both these issues. Fixing 1) means there's no automatic
>> coercion when trying to mix bytes and unicode.
>
> Fine, so programs will have to do it themselves...

Yes, they can finally handle bytes and Unicode data correctly and safely. 
Having byte data turn into Unicode strings unexpectedly makes the behaviour 
of your code hardly predictable and fairly error prone. In Python 3, it's 
now possible to do the conversion safely at well defined points in your 
code and rely on the runtime to bark at you when something slips through or 
is mistreated. Detecting errors early makes your code better.

That's a huge improvement. It didn't come for free and the current Python 3 
releases still have their rough edges. But there are few left and the 
situation is constantly improving. You can help out if you want.

Stefan




More information about the Python-list mailing list