zoukankan      html  css  js  c++  java
  • 解决 ElementTree 无法处理中文

    解决 ElementTree 无法处理中文,UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 76-99: ordinal not in range(128)

    ET.fromstring 传进去 unicode 字符串提示 UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 76-99: ordinal not in range(128)。

    encode(‘utf-8′) 后传进去提示 ValueError: multi-byte encodings are not supported,不支持多字节编码。

    python 的中文支持真是头痛,这个如果用 sys.setdefaultencoding=’utf-8’ 可以解决,但是觉得直接为了这个直接修改了全局编码不太好,最后发现可以用如下代码解决:

    https://gist.github.com/GameXG/89b92a9a94456ff2da85

  • 相关阅读:
    Advanced Configuration Tricks
    Reviewing the Blog Module
    Editing and Deleting Data
    Making Use of Forms and Fieldsets
    Understanding the Router
    SQL Abstraction and Object Hydration
    Preparing for Different Databases
    Java学习理解路线图
    Openstack学习历程_1_视频
    CentOS安装Nginx负载
  • 原文地址:https://www.cnblogs.com/alapha/p/7460611.html
Copyright © 2011-2022 走看看