I am trying to read in an excel sheet using xlrd, but I’m having some problems storing Chinese characters.
I am not sure why values get translated when I store it in a list:
Code:
for rownum in range(sh.nrows):
Temp.append(sh.row_values(rownum))
print Temp
Output:
u’\u8bbe\u5168\u96c6\u662f\u5b9e\u6570\u96c6R\uff0c
M=\uff0c
{x|-2<=x<=2}N{x|x<1}\uff0c\u5219bar(M) nn\u7b49\u4e8e
N\n[A]\uff1a
{x|x<-2}[B]\uff1a
{x|-2<1}[C]\uff1a
{x|x<1}[D]\uff1a
{x|-2<=x<1}‘
However when I print out a single cell value, they are printed out correctly as per excel sheet:
Code:
cell_test = sh.cell(1,3).value
print cell_test
Output:
设全集是实数集R,
M={x|-2<=x<=2},N={x|x<1},则bar(M) nn N等于[A]:
{x|x<-2}[B]:
{x|-2<1}[C]:
{x|x<1}[D]:
{x|-2<=x<1}
What should I do to get Python to store the above data at its original value?
Thanks!
The values should be the same. They are just displayed differently.
This example shows that when you print a list individual items are displayed using
repr()function, but a string is displayed as is (unicode strings are encoded to bytes first).