0
我在Python中遇到了一些Unicode错误,试图打印一些字符串,并使用以下代码从第二个项目符号中解答了大部分错误: UnicodeEncodeError: 'charmap' codec can't encode - character maps to <undefined>, print functionPython中列表对象的Unicode错误
# -*- coding: utf-8 -*-
import sys
print sys.stdout.encoding
print u"Stöcker".encode(sys.stdout.encoding, errors='replace')
print u"Стоескер".encode(sys.stdout.encoding, errors='replace')
但是,我试图在列表对象上使用它时出现错误。它给了我一个错误,列表中没有属性“编码”。
有人有一个干净的解决方案来解决这个问题吗?
任何帮助表示赞赏!
应用'encode()'列出项目,而不是列表本身 – dm295
请添加你得到的输出(错误文本)和你的python版本。在这里...... –
_'''它给了我一个错误,表中没有属性“encode”。'''_这是因为'list'没有'encode'方法,这是[方法在'str'或'unicode'](https://docs.python.org/2/library/stdtypes.html#str.encode) –