Answer the question
In order to leave comments, you need to log in
How to edit XML file using Python?
Hello!
I'm still new to python, I'm learning, trying to write small scripts.
Faced with the need to automate routine work with XML files.
I can not find information on editing the XML file.
There is a need to periodically do the same actions with the content. Cut a branch in an XML file and paste it elsewhere in the same file. Please tell me the easiest way to do this. If there are examples - I will be grateful. I look while towards use of ElementTree. According to the instructions, I only find how to parse XML, extract data from it, write it to another file, but I can’t find editing.
Answer the question
In order to leave comments, you need to log in
in general, if you are going to continue doing this, then first you better learn English
google "edit xml with python"
my_file = open(filename, "r")
lines_of_file = my_file.readlines()
lines_of_file.insert(-1, "Новая строка")
my_file.writelines(lines_of_file)
I don't understand what you were looking for. Official documentation "The ElementTree XML API", section " Modifying an XML File ".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question