[Python-Dev] len(chr(i)) = 2?

Alexander Belopolsky alexander.belopolsky at gmail.com
Sun Nov 21 23:13:22 CET 2010


On Fri, Nov 19, 2010 at 4:43 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>> In my opinion, the question is more what was it not fixed in Python2. I suppose
>> that the answer is something ugly like "backward compatibility" or "historical
>> reasons" :-)
>
> No, there was a deliberate decision to not support that, see
>
> http://www.python.org/dev/peps/pep-0261/
>
> There had been a long discussion on this specific detail when PEP 261
> was written, and in the end, an explicit, deliberate, considered
> decision was made to raise a ValueError.
>

Yes, the existence of PEP 261 was one of the reasons I was surprised
that a change like this was made without a deliberation.   Personally,
I've never used chr() or ord() other than on the python command
prompt.  Processing text one character at a time is just too slow in
Python.  So for my own use cases, the change is quite welcome.  I also
find that with bytes() items being int in 3.x more or less removes the
need for ord().  On the other hand any 2.x program that uses unichr()
and ord() is very likely to exhibit subtly buggy behavior when ported
to 3.x.  I don't think len(chr(i)) = 2 is likely to cause problems,
but map(ord, s) not being an iterator over code points is likely to
break naive programs.   This is especially true because as far as I
can tell there is no easy way to iterate over code points in a Python
string on a narrow build.


More information about the Python-Dev mailing list