xmltodict does not return a list for one element

前端 未结 3 630
轮回少年
轮回少年 2021-01-17 10:18

The following Code produces an error, if there is only one \"car\" in \"garage\":

import xmltodict

mydict = xmltodict.parse(xmlstringResults)    
for carsIn         


        
3条回答
  •  -上瘾入骨i
    2021-01-17 10:38

    This problem is discussed in this issue on Github. The xmltodict package now supports

    d = xmltodict.parse(s, force_list={'car'})
    

    Although this still doesn't create an empty list if the field is absent.

提交回复
热议问题