我无法显示unicode项目u'\u201d'
.我没有其他unicode项目的问题.我使用了UTF-8,但是这个角色在我的代码上出现并下了地狱.我在翻译中尝试了不同的东西.但基本上在哪里:
c = u'\u201d'
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Traceback (most recent call last):
File "<pyshell#154>", line 1, in <module>
c.decode('utf-32')
File "C:\Python27\lib\encodings\utf_32.py", line 11, in decode
return codecs.utf_32_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201d' in position 0: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我需要在GUI中显示它,以便检查输出,然后将其存储为纯文本. 在python中转换unicode字符串 解释了一下,但是我仍然明显遗漏了一些东西.
如果您收到此异常,那么您正在尝试调用.decode()
unicode字符串.您应该只调用.decode()
字节字符串,并且只调用.encode()
unicode字符串.否则,解释器将首先使用默认编解码器(通常为"ascii")隐式编码或解码字符串,这是坏消息.
一般来说,我建议仔细阅读http://farmdev.com/talks/unicode/ ...
归档时间: |
|
查看次数: |
6328 次 |
最近记录: |