code:
if n_list[i]=="國產IC":
pass
錯誤信息:
UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode
原因:
字符串中有中文,在python做比較時,因爲編碼方式不同而導致
解決辦法:
添加系統中文編碼方式
# -*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
或者對需要對比的中文字符進行編碼:
#單獨編碼
cnVar = cnVar.decode('utf-8')
#單獨編碼
if n_list[I] == "國產IC".decode('utf-8'):
pass
這樣處理就不會報錯了