ExpatError:使用xmltodi时内存不足

2024-09-21 03:06:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用python中的以下代码解析一个大的XML文件(300MB)

import xmltodict


def handle(path, item):
    print path
    print item
return True


file = open('large_file.xml','r')

str = file.read()

xmltodict.parse(str, item_depth=3, item_callback=handle)

我可以解析100MB的XML文件,但是当我尝试使用300MB的大文件时,我得到了

ExpatError: out of memory: line 1, column 0

是否有其他库或方法可以处理更大的XML文件?还是我做错了? 请指教。


Tags: 文件path代码importtruereturndefxml

热门问题