如何在python中使用西班牙语进行编码和解码 [英] How to encode and decode from spanish in python

查看:407
本文介绍了如何在python中使用西班牙语进行编码和解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下用python 2.7编写的代码

I have the following code written in 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)

感谢任何帮助,在此先感谢

Any help appreciated, thanks in advance

推荐答案

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

这样做。

这篇关于如何在python中使用西班牙语进行编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆