【发布时间】:2016-08-14 01:10:11
【问题描述】:
我正在使用 PYTHON 将 excel(xlsx) 文件转换为 CSV,我收到以下错误消息。
代码: 导入 xlrd 导入csv
with xlrd.open_workbook('a_file.xlsx') as wb:
sh = wb.sheet_by_index(0) # or wb.sheet_by_name('name_of_the_sheet_here')
with open('a_file.csv', 'wb') as f:
c = csv.writer(f)
for r in range(sh.nrows):
c.writerow(sh.row_values(r))
错误信息: 回溯(最后一次调用):文件“C:\Python27\Scripts\1.py”,第 9 行,在 c.writerow(sh.row_values(r)) UnicodeEncodeError: 'ascii' codec can't encode character u' \xbd' 在第 4 位:序数不在范围内(128)
关于解决错误的任何提示?
【问题讨论】: