[Tutor] unicode problem

Paul Tremblay phthenry@earthlink.net
Mon Apr 28 02:10:01 2003


When I use Sax, I am getting a unicode problem.

If I put an "ö" in my file (ö), then sax translates this to a
unicode string:

u'?' (some value)

I then cannot parse the string. If I try to add to it:

my_string = my_string + '\n'

Then I get this error:


 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)

The only way to get around this problem is to convert the text to ascii
beforehand:


        for x in my_string:
            if ord(x) > 127:
                num = ord(x)
                x = "&#" + str(num) + ";"
            new_string = new_string + x

I don't want to use entities, though. Since my script converts to text,
I need for the text to be represented as characters up to 256.

Thanks

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************