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

  • 相关阅读:
    VB6SP6极度精简兼容绿色版
    Upnp资料整理
    RevMan简单入门指南
    小程序 --flex
    IV
    2017-10-27错误日志
    170616_2
    170616
    2017-06-07
    111111112222
  • 原文地址:https://www.cnblogs.com/alapha/p/7460611.html
Copyright © 2011-2022 走看看