gpt4 book ai didi

python - 如何在python中从西类牙语编码和解码

转载 作者:太空狗 更新时间:2023-10-29 21:37:27 25 4
gpt4 key购买 nike

我用 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

这样就可以了。

关于python - 如何在python中从西类牙语编码和解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20935151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com