-1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Please try to find solutions of your own before you ask questions. You could have found the solution to this problem very quickly by searching for something like "replacing part of string in python" – fogx Feb 23 '19 at 22:12
  • Possible duplicate of [Change one character in a string?](https://stackoverflow.com/questions/1228299/change-one-character-in-a-string) – fogx Feb 23 '19 at 22:17

1 Answers1

0

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
Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53