为什么在Anaconda命令提示符下写入拒绝xlrd输出?

时间:2017-12-31 15:07:25

标签: python-3.x anaconda xlrd

我正在使用Windows计算机。

脚本从Excel电子表格中提取数据(数字和字符串),对其进行操作,然后使用write输出。它工作正常,直到我开始将它应用于具有Unicode字符的东西,此时我得到了

UnicodeEncodeError: 'charmap' codec can't encode character '\u0159' in position 3: character maps to <undefined>

我试过

chcp 65001
set PYTHONIOENCODING=utf-8

希望print的{​​{3}}适用于write,但它没有。

这是代码(在我删除了我认为无关的所有内容之后)。

class listing:
    def __init__(self,input8):
        self.personname=input8
    def listing_string(self):
        return self.personname+'\n'

import xlrd
workbook=xlrd.open_workbook('test.xlsx')
worksheet=workbook.sheet_by_name('Sheet1')
myfile = open('test', 'w')
for y in range(worksheet.nrows-1):
    person=worksheet.cell(y+1,15).value
    myListing=listing(person)
    myfile.write( myListing.listing_string() )
myfile.close()

0 个答案:

没有答案