如何在python中从西班牙语进行编码和解码

ale*_*tet 7 python unicode encoding python-2.7

我有以下代码用python 2.7编写

# -*- coding: utf-8 -*-    
import sys

_string = "años luz detrás"
print _string.encode("utf-8")
Run Code Online (Sandbox Code Playgroud)

这会引发以下错误:

print _string.encode("utf-8")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示感谢,提前谢谢

Ble*_*ers 6

u之前添加"

>>> _string = u"años luz detrás"
>>> print _string.encode("utf-8")
años luz detrás
Run Code Online (Sandbox Code Playgroud)

这样做.