我使用的是xlrd
和cx_freeze
。UnicodeEncodingError
現在,當我試圖從Excel文件讀取,它顯示了一個錯誤,當它來到了「」標記:
UnicodeEncodeError: 'charmap' codec can't encode character "\u2019" in position 12: character maps to <undefined>
from xlrd3 import *
book= open_workbook('s1.xls')
sheet=book.sheet_by_index(0)
import sys
from encodings import *
from codecs import *
def pr():
global row,col
if isinstance((sheet.cell(row,col).value), float):
cell = sheet.cell(row,col)
cell_value = cell.value
cell_value1= int(cell.value)
s=[]
s.append(cell_value1)
print (s)
s=[]
else:
cell = sheet.cell(row,col)
cell_value = cell.value
s=[]
s.append(cell_value)
print (s)
s=[]
def co():
x=input("'S'earch again or 'Q'uite?: ")
if x == 'S' or x=='s':
search()
elif x == 'Q'or x == 'q':
sys.exit(0)
else:
print ('Please enter a Vailed answer: ')
co()
def search():
global row,col
s=[]
a=(input("Enter Search : "))
for row in range(sheet.nrows):
for col in range(sheet.ncols):
s.append(str(sheet.cell(row,col).value))
if a in (str(sheet.cell(row,col).value)):
for col in range(sheet.ncols):
pr()
else:
s=[]
co()
search()
這是代碼
我不確定我能幫上什麼忙,但我認爲任何能夠幫助的人都需要看到您寫入的文件中讀取的代碼。呈現錯誤是好的,但調用異常時運行的代碼甚至更加關鍵。 – PyNEwbie
感謝pynewbie的評論,那就是代碼 –
這本質上是一個http://stackoverflow.com/questions/11050292/prevent-encoding-errors-in-python的副本,只有很多無關的文本和有用的指針,像堆棧軌跡一樣,被刪除。我認爲它應該被標記爲重複。 –