0
我想將dblp數據集的xml文件解析爲csv文件。現在我正在用lxml模塊做這件事,並測試不同的函數以查看它們返回的內容。 然而,當我運行下面的代碼:ValueError:針對dblp數據集的關閉文件錯誤的I/O操作
with open('F:\\21up\\Data\\dblp.xml', 'rb') as f:
context = etree.iterparse(f, dtd_validation=True, events= ("start","end"))
context = iter(context)
event, root = next(context)
for event, ele in context:
print event
print ele
我得到了ValueError異常:
Traceback (most recent call last):
File "F:\21up\Data\XML2CSV", line 35, in <module>
iterpar()
File "F:\21up\Data\XML2CSV", line 28, in iterpar
event, root = next(context)
File "iterparse.pxi", line 208, in lxml.etree.iterparse.__next__ (src\lxml\lxml.etree.c:131498)
ValueError: I/O operation on closed file
我不知道這是如何發生。我用Google搜索了它,但還沒有找到合適的解釋。任何人都可以告訴我如何解決它?非常感謝。
問題解決!非常感謝你! – Wulipapa