[Tutor] unicode problem
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Mon Apr 28 13:14:02 2003
> The error message you report:
>
> > File "/home/paul/lib/python/paul/format_txt.py", line 159, in r_border
> > line = line + filler + padding + border + "\n"
> > UnicodeError: ASCII decoding error: ordinal not in range(128)
>
>
> doesn't smell right to me --- for the life of me, I can't imagine why
> string concatenation would raise that kind of error.
Oh. Never mind.
###
>>> x, y = u'\xf6', '\xf6
>>> x + y
Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeError: ASCII decoding error: ordinal not in range(128)
###
Well, at least now we have a test case we can work on. *grin*
I think that the concatentation causes Python to raise the second string y
up as a unicode string. At least, it looks like that unicod()ing a
high-byte character can cause the encoding error:
###
>>> unicode('\xf6')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeError: ASCII decoding error: ordinal not in range(128)
###
I'm actually not quite sure how to solve this yet; I'm not familiar with
Unicode at all, so I think I might need to tinker with this problem a bit.