【问题标题】:python encoding and decoding stringspython编码和解码字符串
【发布时间】:2011-08-07 01:23:22
【问题描述】:

我正在从文件中读取 Python 中的名字和姓氏,并且在编码时遇到问题。我想打印出名称,但收到“UnicodeEncodeError: 'charmap' codec can't encode character '\u021b' in position 11: character maps to undefined”这个代码:

    first = obj.first_name.encode('utf-8')
    last = obj.last_name.encode('utf-8')
    first = first.decode('utf-8')
    last = last.decode('utf-8')
    print(first)

有什么问题?

【问题讨论】:

    标签: python string


    【解决方案1】:

    问题是您的输出终端/控制台无法显示ț。如果您使用的是 Windows,请在运行脚本之前尝试 chcp 65001

    【讨论】:

      猜你喜欢
      • 2012-03-25
      • 1970-01-01
      • 2017-11-01
      • 1970-01-01
      • 2012-07-05
      • 2013-06-08
      • 2012-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多