print 'opening'f = open('large.xml','r')data = f.read()f.close()print 'Converting'newJsON = xmltodict.parse(data)print 'Json DumPing'newJsON = Json.dumps(newJsON)print 'Saving'f = open('newJson.Json','w')f.write(newJsON)f.close()
错误:
Python(2461) malloc: *** mmap(size=140402048315392) Failed (error code=12)*** error: can't allocate region*** set a breakpoint in malloc_error_break to deBUGTraceback (most recent call last): file "/Users/user/Git/Resources/largexml2Json.py",line 10,in <module> data = f.read()MemoryError解决方法 许多Python XML库支持递增地解析XML子元素,例如标准库中的xml.etree.ElementTree.iterparse和xml.sax.parse.这些函数通常称为“XML Stream Parser”.
您使用的xmltodict库也具有流模式.我认为它可以解决你的问题
https://github.com/martinblech/xmltodict#streaming-mode
总结以上是内存溢出为你收集整理的Python – 将非常大(6.4GB)的XML文件转换为JSON全部内容,希望文章能够帮你解决Python – 将非常大(6.4GB)的XML文件转换为JSON所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)