我有一张excel表,如下所示,我需要读取单元格中的值并与另一个文件进行比较。
0 1 2 3 4 5
1100 ᄀ ᄁ ᄂ ᄃ ᄄ ᄅ
1120 ᄠ ᄡ ᄢ ᄣ ᄤ ᄥ
1140 ᅀ ᅁ ᅂ ᅃ ᅄ ᅅ
我在谷歌搜索打开并阅读python中excel表格内容后写了下面的代码
import xlrd
file_location = "C:/Users/yepMe/Desktop/try/language.xlsx"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(3)
data = [[sheet.cell_value(r,c) for c in range(sheet.ncols)] for r in range(sheet.nrows)]
print type(data)
print data[1][0]
现在这不会抛出任何错误并打印0.0,但是当我尝试打印任何其他试图打印像print data[2][2]
这样的韩文字符的值时,会出现以下错误:
print data[2][2]
File "C:\Python27\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u1121' in position 0: character maps to <undefined>,
请告诉我要获得韩国字符需要做些什么。
如果我print ord(data[2][2])
,它会打印unicode代码点,但是当我试图循环它时:
for char in data:
decVal = ord(char)
Traceback (most recent call last):
File "C:\Users\amondapr\Desktop\korean\fonts\ttfq_protima.py", line 78, in <mo
dule>
decVal = ord(char)
TypeError: ord() expected string of length 1, but list found
它给出了上述错误我如何获取值,我做错了什么?