[Python-Dev] unichr

Ka-Ping Yee ping@lfw.org
Wed, 7 Feb 2001 08:12:33 -0800 (PST)


On Tue, 6 Feb 2001, Paul Prescod wrote:
> Does anyone have an example of real code that would break if unichr and
> chr were merged? chr would return a regular string if possible and a
> Unicode string otherwise. When the two string types are merged, there
> would be no need to deprecate unichr as redundant.

At the moment, since the default encoding is ASCII, something like

    u"abc" + chr(200)

would cause an exception because 200 is outside of the ASCII range.

So if unichr and chr were merged right now as you suggest,

    u"abc" + unichr(200)

would break: unichr(200) would have to return '\xc8' (not u'\xc8')
for compatibility with chr(200), yet the concatenation would fail.
You can see that any argument from 128 to 255 would cause this
problem, since it would be outside the definitely-8-bit range and
also outside the definitely-Unicode range.


-- ?!ng