lxml.etree._ElementUnicodeResult转化为其他字符类型

仅限python3

今天在用到lxml库时遇到了这样一个问题

Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/form_report_traffic.py", line 39, in <module>
    total_drate += (list1[number][3])
TypeError: unsupported operand type(s) for +=: 'int' and 'lxml.etree._ElementUnicodeResult'

在用到xml获取到的数字数据想进一步处理,遇到了这个问题。百度了一遍答案千篇一律的说是编码问题。

想了很久尝试了下直接用强制转化居然可以用。

将上面的错误代码改为:

total_urate += float(list1[number][3])

 就ok了。

实际上就是直接加入你想转换的数据类

posted @ 2018-08-06 11:37  biyeee  阅读(9530)  评论(0编辑  收藏  举报