-3

好的,我有一个要解析的大 xml 文档,所以我可以将它们添加到数据库中。

fileIn = open(path + 'POTS_Table'+ date + '.xml', 'r') ## gets file from location
file = fileIn.read() ## reads all data in file and saves as variable file
parser = etree.XMLParser(recover=True) ## to help with broken xml attributes
tree= etree.parse(fileIn, parser=parser) 

只要我打印结果,这工作正常,但是当我尝试

parameters ={treeAttributesDictionary}
update= '''update table set column1:parameters1 '''
change=update.format(**parameters)
c.execute(change)

我得到这个错误

File "./sqltest.py", line 1932, in <module>
    main(path,date)
File "./sqltest.py", line 1912, in main
    addPots(path,date)     
File "./sqltest.py", line 1330, in addPots
     tree = ET.fromstring(file, parser=parser) ## parses the information in the XML file   , parser=parser
 TypeError: XML() got an unexpected keyword argument 'parser'

谁能帮我?

4

1 回答 1

0

ET.fromstring的文档没有提到解析器属性,这是您的错误告诉您的(甚至给了您行号)。

但是,您的代码在许多其他方面似乎有些混乱。我建议您花更多时间研究一般的 Python 文档。例如,我不确定parameters ={treeAttributesDictionary}应该做什么。

于 2013-12-07T09:00:03.930 回答