【问题标题】:Decode utf-8 in python 2.7在 python 2.7 中解码 utf-8
【发布时间】:2015-07-16 19:19:06
【问题描述】:

我正在学习 python 3 中的教程,但我正在使用 python 2.7,如何为 python 2.7 解码 utf-8?

使用的代码是:

data = data.readall().decode("utf-8")

但我得到一个 AttributeError:

AttributeError: addinfourl instance has no attribute 'readall' 

【问题讨论】:

  • 你的错误与encoding完全无关,你想用readall()实现什么数据类型?

标签: python-2.7 python-3.x utf8-decode


【解决方案1】:

我没有意识到 python 3 中的字符串和字节之间存在差异,而 python 2 中没有那么大的差异。

以下代码适用于 python 2:data = urllib2.urlopen(dataLink).read()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-10
    相关资源
    最近更新 更多