[Tutor] unicode problem

Paul Tremblay phthenry@earthlink.net
Mon Apr 28 11:44:02 2003


No, this won't fix the problem. I should have been a bit more clear. In
my original file, I actually typed 'ö'. When I use Sax, it
translates this to unicode. Since I am using a legal entity, I believe
that Sax translates it to pure unicode. 

I did try your solution, I get a similar problem. The code chokes as
soon as I try 

 x x.encode("latin-1")

I get the same out of range error.

Thanks

Paul

On Mon, Apr 28, 2003 at 10:49:32AM +0200, Michael Janssen wrote:
> 
> On Mon, 28 Apr 2003, Paul Tremblay wrote:
> 
> > 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)
> 
> I don't know, if this is also suitable for your situation, but it can
> solve errors with "not in range":
> 
> >>> u = u'ä'
> >>> u
> u'\xe4'
> >>> print u
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> UnicodeError: ASCII encoding error: ordinal not in range(128)
> >>> print u.encode("latin-1")
> ä
> 
> unicode string is converted to string
> 
> The name of the encoding may also be iso-8859-1. I suppose legal values
> for encoding are such for that files under /path/to/pathon/lib/encodings
> are found. encode takes a second parameter controlling how to deal with
> errors - compare help("".encode).
> 
> Michael
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

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