【发布时间】:2021-09-05 08:13:34
【问题描述】:
我有一个 XML 跟踪文件,该文件的大小约为 350 Mb。当我一次使用以下代码时,它会产生内存已满问题,而另一次会产生关于无法解析文件的错误。解析这么大的文件应该怎么做?是否使用不同的方法进行解析?
root = ET.parse('E:/software/jm_16.1/bin/tracefile.xml').getroot()
lst = root.findall('AVCTrace/Picture/SubPicture/Slice/MacroBlock')
for item in lst:
print (item.get('QP_Y'))
I also produce a smaller file and based on the above file and the variable `lst` is empty!!. do you know what is the problem?
my XML trace file is as follows:
I also need to extract X tag and Y tag in Macroblock. for this I used <MacroBlock num="8158">
<SubMacroBlock num="0">
<Type>1</Type>
<TypeString>B_L0_8x8</TypeString>
<MotionVector list="0">
<RefIdx>0</RefIdx>
<Difference>
<X>-1</X>
<Y>-2</Y>
</Difference>
<Absolute>
<X>-4</X>
<Y>-6</Y>
</Absolute>
</MotionVector>
</SubMacroBlock>
【问题讨论】:
-
使用
lxml -
谢谢。使用 ET 我可以解析它,但是当我使用 item.get('QP_Y') 时它什么也得不到,而且它们都是无。如何实现 QP_Y 的值?例如在上面的例子中是 28。
-
lst 是一个包含 979200 个元素的列表。
-
@JonSG 你的评论是关于我最后一个关于寻找 QP_Y 值的问题?
标签: python python-3.x xml-parsing