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了。

實際上就是直接加入你想轉換的數據類


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM