gpt4 book ai didi

python - 在 XML 节点中设置自增属性

转载 作者:数据小太阳 更新时间:2023-10-29 02:43:17 24 4
gpt4 key购买 nike

我正尝试在我的 XML 的一个节点中设置一个属性,如下所示:

rank = 1
for photo in s:
image = feed.createElement('Image')
images.appendChild(image)
image.setAttribute("rank", rank)
p = feed.createTextNode(str(main_url+photo.display.url))
image.appendChild(p)
rank += 1

然而,这会导致错误:'int' object has no attribute 'replace' in reference to the line: image.setAttribute("rank", rank)我错过了什么?

最佳答案

.setAttribute method需要一个字符串,所以你必须转换它:

image.setAttribute("rank", str(rank))

关于python - 在 XML 节点中设置自增属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2127291/

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