我有一个这样的脚本:
#!/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这在这里很有用。这些链接包含更多信息,可以帮助您解决此问题:
- Python Unicode 指南 http://www.amk.ca/python/howto/unicode
-
Python 内置类型 http://docs.python.org/library/stdtypes.html(参见第 6.6 节)。
- Python 中的 Unicode,完全揭秘 http://farmdev.com/talks/unicode/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)