python 3.x 中出现 UnicodeEncodeError: 'ascii' codec can't encode character '\uff1a' in position 14: ordinal not in range(128)报错,为什么
时间: 2023-12-11 11:28:48 浏览: 245
这个错误是因为在使用 ASCII 编码输出时,遇到了非 ASCII 字符,导致无法编码。解决方法可以是在输出前将字符串转换成 UTF-8 编码,或者改变输出编码方式。具体可以参考以下代码:
```
import sys
# 将输出编码方式改为 UTF-8
sys.stdout.encoding = 'utf-8'
# 或者在输出前进行转换
print('你好'.encode('utf-8'))
```
阅读全文
相关推荐







