Python3中遇到UnicodeEncodeError: 'ascii' codec can't encode characters in ordinal not in range(128)
程序员文章站
2022-03-20 23:29:03
...
在python3中遇到如下错误
UnicodeEncodeError: 'ascii' codec can't encode characters in ordinal not in range(128)
这是编码的问题,在代码中加入如下代码即可
import sys
import io
sys.stdout = sys.__stdout__ = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8', line_buffering=True)
sys.stderr = sys.__stderr__ = io.TextIOWrapper(sys.stderr.detach(), encoding='utf-8', line_buffering=True)
上一篇: python的输入
下一篇: visdom 可视化使用
推荐阅读
-
UnicodeEncodeError:'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)
-
macOS解决sublime text3运行python3报:UnicodeEncodeError: 'ascii' codec can't encode characters in position
-
UnicodeEncodeError:'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)
-
Python3中遇到UnicodeEncodeError: 'ascii' codec can't encode characters in ordinal not in range(128)