美文网首页
python3中UnicodeEncodeError: 'asc

python3中UnicodeEncodeError: 'asc

作者: 不懒狮Blaise | 来源:发表于2018-03-07 15:41 被阅读0次

python3下print下面字符报了错误。

>>> print('\u00bb')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character '\xbb' in position 0: ordinal not in range(128)

怀疑到了print方法,网上找到2个解决方案:
1.设置标准输出的编码

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')

2.修改系统设置的编码

如果安装系统为中文系统,则修改【LANG=“zh_CN.UTF-8”】
如果安装系统为英文系统,则修改【LANG=“en_US.UTF-8”】保存文件。

相关文章

网友评论

      本文标题:python3中UnicodeEncodeError: 'asc

      本文链接:https://www.haomeiwen.com/subject/vfmjfftx.html