我有以下用python 2.7编写的代码
# -*- coding: utf-8 -*-
import sys
_string = "años luz detrás"
print _string.encode("utf-8")
这将引发以下错误:
print _string.encode("utf-8")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
任何帮助表示赞赏,在此先感谢
u
在之前添加"
>>> _string = u"años luz detrás"
>>> print _string.encode("utf-8")
años luz detrás
这样就可以了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句