Degree symbol (UTF-8 > ASCII)

Peter Clark pc451 at yahoo.com
Wed Apr 16 21:20:28 EDT 2003


"Dennis Reinhardt" <DennisR at dair.com> wrote in message news:<TUhna.928$cq2.100423716 at newssvr13.news.prodigy.com>...
> > I'm working with a xml document which doesn't include an encoding,
> 
> The lack of an encoding is your problem.  Pick an encoding which defines 256
> characters, not 128, if you want to represent chr(176).in a single byte.
    I'm sorry, upon re-reading my first message, I realize that I did
not describe the problem adequately enough. Let me see if I can try
again.
    When I try chr(176).encode('latin-1') I get the following message:
UnicodeError: ASCII decoding error: ordinal not in range(128). But
when I try 'print chr(176)' I get the degree symbol, which is what I
want. Yet when I try inserting this into the XML stream, I get the
following error:

    w += [chr(176) + scale.strip()]
UnicodeError: ASCII decoding error: ordinal not in range(128)

    I've tried changing its encoding to 'utf-8' as well with
chr(176).encode('utf-8'), but that just returns the same error. This
doesn't make sense: if 'print chr(176)' works fine, why doesn't it
work later on? In a nut shell, all I want to do is add the degree
character to a string contained within a list. That doesn't seem hard
at all, but I'm completely stumped.




More information about the Python-list mailing list