【问题标题】:python special charecter issue in 2.7 ( utf8' codec can't decode ) [duplicate]2.7中的python特殊字符问题(utf8'编解码器无法解码)[重复]
【发布时间】:2018-07-01 20:33:40
【问题描述】:

我有一个这样的数组

 Address=['fâch','Pyrénées']
    print(Address)

这里的数组有特殊字符。我该如何解决这个问题

错误:utf8' 编解码器无法解码位置 0 中的字节 0xe1:无效的继续字节

【问题讨论】:

    标签: python python-2.7 utf-8


    【解决方案1】:

    在 python2.7 中试试这个:

    # -*- coding: utf-8 -*-
    Address = ['fâch', 'Pyrénées']
    for i in Address:
         print i
    

    注释行应该在文件的顶部。

    【讨论】:

    • 哇哦。为我工作:)
    【解决方案2】:

    你可以这样使用:

    Address=['fâch','Pyrénées']
    for i in Address:
        value = unicode(i, 'utf-8')
        print value
    

    这应该会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 2016-08-03
      • 2012-08-08
      • 1970-01-01
      相关资源
      最近更新 更多