我又多了一個錯誤需要修正。UnicodeEncodeError與csvwriter
row = OpenThisLink + titleTag + JD
try:
csvwriter.writerow([row])
except (UnicodeEncodeError, UnicodeDecodeError):
pass
這給出了錯誤(此字符: 「N」)我試圖通過使用該方法here來解決這個
row = OpenThisLink + str(titleTag) + JD
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 51: ordinal not in range(128)
。但是,
>>> title = "hello Giliciński"
Unsupported characters in input
u = unicode(title, "latin1")
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
u = unicode(title, "latin1")
NameError: name 'title' is not defined
>>> title = "ń" Unsupported characters in input
根據文檔:
不像一個類似的案件與
UnicodeEncodeError
,這樣的失敗未必能夠避免。
事實上,我的例外似乎並沒有工作。有什麼建議麼?
謝謝!
鏈接到文檔:http://wiki.python.org/moin/UnicodeDecodeError – Zeynel 2009-12-04 00:08:06