Python3输出中文错误
python3中输出中文,可能出现如下错误 UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) 代码如下 s="中文" print(s) 解决此类问题,添加如下代码即可: import sys, locale, os utf8_stdout = os.fdopen(sys.stdout.fileno(), mode='w', encoding='utf-8', closefd=False) sys.stdout = utf8_stdout
- 2.95k
- 2
- 阅读全文