向文件写入字符串时出错。在
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 16: ordinal not in range(128)
问题是我已经把绳子清理干净了。但不知道为什么这样不行
这是我清理字符串的代码
^{pr2}$你知道我在清理绳子的时候遗漏了什么吗?在
我知道这个问题被问了很多次。但我的问题是这个问题最常见的解决方法是
text.encode('utf-8')
这对我没用。在
我也试过了
text.encode('utf-8', 'ignore')
没用
不知道它给你带来了什么错误。我刚刚在windows上的python 2.7.10中测试了这一点:
该文件也包含相同的文本。在
这可能是另一种选择:
^{pr2}$你过滤掉了不在ascii中的字符,所以你不必担心unicode。在
相关问题 更多 >
编程相关推荐