【发布时间】:2012-12-13 22:36:12
【问题描述】:
我在这一行遇到了与 Unicode 相关的问题:
strToCompare = str(self.modelProxy.data(cellIndex, Qt.DisplayRole).toString()).lower()
错误是:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 5: ordinal not in range(128)
这是因为数据是从数据库中可能包含 unicode 字符的字段中检索的。即使我添加了unicode() 函数来转换为Unicode,错误仍然存在。
【问题讨论】:
-
你能把字符串贴出来吗?
-
字符是\xe9,意思是é。问题是我只有在客户端机器上才有这个问题,即使我们有相同的 python 版本(2.6)