dicttoxml,数字为键

时间:2018-12-17 04:46:20

标签: python dicttoxml

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'

1 个答案:

答案 0 :(得分:1)

检查一次错误将使您了解发生了什么问题。

“ ArrayWithDigitKey”的键必须为整数,但必须为字符串形式。

因此,您必须按如下所示定义字典,并且字典应重新开始工作

if let string = UIPasteboard.general.string {
  // use the string, for example:
   yourTextField.text = string
}else {
 //There is no text in Pasteboard
}

让我知道是否需要其他帮助。