Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用xml.etree.ElmentTree时出现类型错误_Python_Xml - Fatal编程技术网

Python 使用xml.etree.ElmentTree时出现类型错误

Python 使用xml.etree.ElmentTree时出现类型错误,python,xml,Python,Xml,我试图根据一些数字测试xml文件中的属性。在属性上运行type()时(在本例中为currentNote): 该类型打印为 但是,如果我将最后一行更改为: print type(int(currentNote)) 我明白了: TypeError: int() argument must be a string or a number, not 'NoneType' 不确定发生了什么-似乎我误解了etree解析器返回的内容 currentNote = note.get("default-x")

我试图根据一些数字测试xml文件中的属性。在属性上运行
type()
时(在本例中为
currentNote
):

该类型打印为

但是,如果我将最后一行更改为:

print type(int(currentNote))
我明白了:

TypeError: int() argument must be a string or a number, not 'NoneType'
不确定发生了什么-似乎我误解了etree解析器返回的内容

currentNote = note.get("default-x")
get
如果与键不匹配,则默认情况下返回
None

不能从
非类型
生成
整数

In [51]: int(None)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-51-3f3b1d3c7325> in <module>()
----> 1 int(None)

TypeError: int() argument must be a string or a number, not 'NoneType'
[51]中的
int(无)
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
---->1整数(无)
TypeError:int()参数必须是字符串或数字,而不是“NoneType”

您应该在循环中打印
note
,以确认数据是否符合预期。

谢谢,但这也会返回一个值。哎呀,除了第一个!谢谢我只是想试试:把它去掉。我不是指类型,我是指确切的值<代码>打印便笺
打印便笺。在循环中获取(“默认-x”)
。啊。我懂了。我明白了-第一个仍然是罪魁祸首。谢谢
In [51]: int(None)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-51-3f3b1d3c7325> in <module>()
----> 1 int(None)

TypeError: int() argument must be a string or a number, not 'NoneType'