问题:
UnicodeEncodeError: 'ascii' codec can't encode character u'**' in position **: ordinal not in range(128)
解决方案:
1、试过在python文件前添加encoding utf-8没有成功;
2、试过
import sys
reload(sys)
sys.setdefaultencoding('utf8') 有效,但是在运行过程中不知什么原因导致不显示输出内容。
3、最后的方法,将string转换为utf-8格式,即
temp.encode('utf-8')
本文介绍了解决Python中UnicodeEncodeError的具体步骤。通过调整系统默认编码为UTF-8,并使用字符串的encode方法,确保了所有字符都能正确编码,避免了错误的发生。

1815

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



