Here's an example of how to save input from a list to an XML file in Python:
main.py448 chars19 lines
In this example, we first import the xml.etree.ElementTree
module. Then we define our list my_list
and create a new root element fruits
.
Next, we loop through the list and create a new child element fruit
for each item in the list. We set the text of each child element to the corresponding item in the list.
After we have created the entire XML document, we create an ElementTree
object from the root element and write the XML document to a file called fruits.xml
.
You can modify this example to work with your specific list and file output format.
gistlibby LogSnag