Q:

Set value for a attribute in xml while send POST request with xml body in Python

I am using Python program where I am sending a GET request; in response I am getting a xml body. From that xml body I have to change few attribute values and again send a post request.
I have already tried:
a = '14256601101'
xml ="""<?xml version="1.0" encoding="UTF-8"?><nms:provision xmlns:nms="urn:oma:xml:rest:netapi:nms:1"><attributeList><attribute><name>MSISDN</name><value>%str(a)</value></attributeList></nms:provision>"""
print xml

Here I want %str(a) to be replaced by 14256601101.

A:

Use string.format() - replace %str(a) with {} and call the .format(str(a)) method on the whole string:
a = '14256601101'
xml ="""<?xml version="1.0" encoding="UTF-8"?><nms:provision xmlns:nms="urn:oma:xml:rest:netapi:nms:1"><attributeList><attribute><name>MSISDN</name><value>{}</value></attributeList></nms:provision>""".format(a)
print xml

