我试图使用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文件?还是我做错了? 请指教。
我看到这篇文章:http://boscoh.com/programming/reading-xml-serially.html。
决定使用celementree和iterparse,效果很好。
相关问题 更多 >
编程相关推荐