python2.7
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)
解决方案
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
我使用的IDE是PvDev eclipse的插件,编译提示异常,但是程序可以执行下去。
回头看看我的代码
expect的值传入了中文,故而需要考虑编码的问题.
def execute_result(expect, resultList):
for result in resultList:
print('result is :'+result)
if expect in result:
return True
return False
本文介绍了一种常见的Python运行时错误——UnicodeDecodeError,并提供了解决方案。通过设置默认编码为UTF-8,解决了在Python 2.7环境中处理中文字符串时出现的错误。
862

被折叠的 条评论
为什么被折叠?



