Python unicode:如何测试unicode字符串
我有这样一个脚本:Python unicode:如何测试unicode字符串,python,unicode,Python,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 e
#!/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代码?Python有一个名为Unicode的序列类型,在这里很有用。这些链接包含有关此方面的更多信息:
- (见第6.6节)
如果argset中的sh.cell(i,1).value.encode('cp1252'):
…
Br.我发现了这个,解决了问题:第一个链接不再存在!