Re: Character Encodings and display of strings
- From: "Fredrik Lundh" <fredrik@xxxxxxxxxxxxxx>
- Date: Mon, 13 Nov 2006 15:39:44 +0100
"JKPeck" wrote:
I am trying to understand why, with nonwestern strings, I sometimes get
a hex display and sometimes get the string printed as characters.
With my Python locale set to Japanese and with or without a # coding of
cp932 (this is Windows) at the top of the file, I read a list of
Japanese strings into a list, say, catlis.
With this code
for item in catlis:
print item
print catlis
print " ".join(catlis)
the first print (print item) displays Japanese text as characters..
The second print (print catlis) displays a list with the double byte
characters in hex notation.
The third print (print " ".join(catlis)) prints a combined string of
Japanese characters properly.
According to the print documentation,
"If an object is not a string, it is first converted to a string using
the rules for string conversions"
but the result is different with a list of strings.
a list is not a string, so it's converted to one using the standard list representation
rules -- which is to do repr() on all the items, and add brackets and commas as
necessary.
for some more tips on printing, see:
http://effbot.org/zone/python-list.htm#printing
</F>
.
- Follow-Ups:
- Re: Character Encodings and display of strings
- From: JKPeck
- Re: Character Encodings and display of strings
- References:
- Character Encodings and display of strings
- From: JKPeck
- Character Encodings and display of strings
- Prev by Date: Character Encodings and display of strings
- Next by Date: Re: article on Python 2.5 features
- Previous by thread: Character Encodings and display of strings
- Next by thread: Re: Character Encodings and display of strings
- Index(es):
Relevant Pages
|