Tracy Ann Monteiro Tracy Ann Monteiro - 28 days ago 16
Python Question

How do I write my xml output to a file

I currently have a Python script that does a get request and prints out the data which is in xml format. How do I dump this output to a xml file for parsing?

Answer

Assuming you have a string variable containing the xml data, you can do the following:

with open("output.xml", "w") as f:
    f.write(xmlstr)