以数字为键的 dicttoxml
dicttoxml with number as key
from dicttoxml import dicttoxml
ArrayWithDigitKey={2:"vale"}
xml =dicttoxml(ArrayWithDigitKey)
我收到这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/dicttoxml.py", line 393, in dicttoxml
convert(obj, ids, attr_type, item_func, cdata, parent=custom_root),
File "/usr/local/lib/python2.7/site-packages/dicttoxml.py", line 189, in convert
return convert_dict(obj, ids, parent, attr_type, item_func, cdata)
File "/usr/local/lib/python2.7/site-packages/dicttoxml.py", line 214, in convert_dict
key, attr = make_valid_xml_name(key, attr)
File "/usr/local/lib/python2.7/site-packages/dicttoxml.py", line 145, in make_valid_xml_name
if key.isdigit():
AttributeError: 'int' object has no attribute 'isdigit'
检查一次错误,您就会知道出了什么问题。
'ArrayWithDigitKey'的key需要是int,但是是string形式
因此,您必须按如下方式定义字典,它应该会重新开始工作,
ArrayWithDigitKey={'2':"vale"}
如果您需要任何其他帮助,请告诉我。
from dicttoxml import dicttoxml
ArrayWithDigitKey={2:"vale"}
xml =dicttoxml(ArrayWithDigitKey)
我收到这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/dicttoxml.py", line 393, in dicttoxml
convert(obj, ids, attr_type, item_func, cdata, parent=custom_root),
File "/usr/local/lib/python2.7/site-packages/dicttoxml.py", line 189, in convert
return convert_dict(obj, ids, parent, attr_type, item_func, cdata)
File "/usr/local/lib/python2.7/site-packages/dicttoxml.py", line 214, in convert_dict
key, attr = make_valid_xml_name(key, attr)
File "/usr/local/lib/python2.7/site-packages/dicttoxml.py", line 145, in make_valid_xml_name
if key.isdigit():
AttributeError: 'int' object has no attribute 'isdigit'
检查一次错误,您就会知道出了什么问题。
'ArrayWithDigitKey'的key需要是int,但是是string形式
因此,您必须按如下方式定义字典,它应该会重新开始工作,
ArrayWithDigitKey={'2':"vale"}
如果您需要任何其他帮助,请告诉我。