我有这样的脚本:Python中的Unicode:如何测试针对unicode字符串
#!/Python26/
# -*- coding: utf-8 -*-
import sys
import xlrd
import xlwt
argset = set(sys.argv[1:])
#----------- import ----------------
wb = xlrd.open_workbook("excelfile.xls")
#----------- script ----------------
#Get the first sheet either by name
sh = wb.sheet_by_name(u'Data')
hlo = []
for i in range(len(sh.col_values(8))):
if sh.cell(i, 1).value in argset:
if sh.cell(i, 8).value == '':
continue
hlo.append(sh.cell(i, 8).value)
excelfile.xls包含unicode字符串和我想测试对命令行这些字符串:
C:\>python pythonscript.py päätyö
pythonscript.py:34: UnicodeWarning: Unicode equal comparison failed to convert both arguments to
icode - interpreting them as being unequal
if sh.cell(i, 1).value in argset:
我应该如何修改我的Unicode代码?
我发现这个,它解决了这个问题: http://stackoverflow.com/questions/846850/how-to-read-unicode-characters-from-command-line-arguments-in-python-on- windows – jrara
第一个链接不存在了! – BajajG