I'm trying to set an attribute in one of the nodes for my XML as below:
rank = 1
for p开发者_如何学Choto 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
This however results in the error: 'int' object has no attribute 'replace'
in reference to the line: image.setAttribute("rank", rank)
What am I missing?
The .setAttribute
method expects a string, so you will have to convert it:
image.setAttribute("rank", str(rank))
精彩评论