gpt4 book ai didi

python - Python 中 XML 文件的值比较

转载 作者:太空宇宙 更新时间:2023-11-03 19:03:03 24 4
gpt4 key购买 nike

我的UML图是这样的:

rootNode
|
Book (attribute:name)
|
Table (attribute: Name)
|
TableEntry(attribute: Field, Value)

当我使用此代码时:

for Book in rootNode.getBooks():
print Book.getName()
for Table in Book.getTables():
print Table.getName()
for TableEntry in Table.getTableEntrys():
print TableEntry.getField(), TableEntry.getValue()

输出如下:

Document
T1
F1 V1
F2 V2
F3 V3
F4 V4
F5 V5
F6 V6
T2
F1 V1
F2 V2
F3 V3
F4 V4
F5 V5
F6 V6
Document
T2
F2 V2
F3 V3
F4 V4
F5 V5
F6 V6

我想将每个字段和值的文档(第一个)中的字段和值 ex- F1 和值 V1 与文档(第二个)中的 F1 V1 进行比较。我的两个文件有相同的书名,即“文档”。我还想在两个文件中找到丢失的字段或附加字段,例如 T2 中我的 F1 和 V1 丢失。

最佳答案

最好的解决方案是“==”来比较值

                      and

如果您想与实体进行比较,请使用“is”

例如=>

a=123; b=123;

a is b

输出:

正确

关于python - Python 中 XML 文件的值比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15548916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com