Degree symbol (UTF-8 > ASCII)
Peter Clark
pc451 at yahoo.com
Thu Apr 17 23:11:57 EDT 2003
Steven Taschuk <staschuk at telusplanet.net> wrote in message news:<mailman.1050606359.1431.python-list at python.org>...
> Quoth Peter Clark:
> > Steven Taschuk <staschuk at telusplanet.net> wrote in message news:<mailman.1050548247.26781.python-list at python.org>...
> And scale is a Unicode string, right?
Only because the XML document has no specified encoding, so it
defaults to UTF-8, yes. But all the text is straight ASCII, except of
course for the inclusion of the degree symbol.
> I'd suggest doing all your string assembly with Unicode strings,
> and only encoding to ISO-8859-1 at the output stage. Mixing the
> two kinds of strings is asking for trouble, as you have seen.
You're right, of course. The list is sent to a simple function
that prints it to stdout; the following worked fine, and handles any
integers or floats that might otherwise cause an attribute error:
def printlist(w):
for item in w:
try:
print item.encode('latin-1')
except:
print item
Which is much nicer than having to mess with the strings as they
are added to the list. Thanks.
More information about the Python-list
mailing list