我有以下格式的 xml:
<channel>
<games>
<game slot='1'>
<id>Bric A Bloc</id>
<title-text>BricABloc Hoorah</title-text>
<link>Fruit Splat</link>
</game>
</games>
</channel>
我已经使用 lxml.objectify
解析了这个 xml , 通过:
tree = objectify.parse(file)
可能会有很多 <game>
在下面 <games>
.
我知道我可以生成 <game>
的列表对象通过:
[ tree.games[0].game[0:4] ]
我的问题是,这些对象是什么类,是否有函数可以打印这些对象属于什么类的任何对象?
最佳答案
也许使用
for game in tree.games[0].game[0:4]:
print(lxml.objectify.dump(game))
产生
game = None [ObjectifiedElement]
* slot = '1'
id = 'Bric A Bloc' [StringElement]
title-text = 'BricABloc Hoorah' [StringElement]
link = 'Fruit Splat' [StringElement]
print(game)
显示每个 game
都是一个 lxml.ojectify.ObjectifiedElement .
关于python - 如何打印对象化元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2984665/