Created
January 30, 2019 17:09
-
-
Save igorzakhar/86fd4888682d888ecb8ef8f0e7dd9b9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
import xml.etree.ElementTree as etree | |
a = ['труба', 'светильник', 'кран шаровый'] | |
b = [3, 2, 2] | |
tree = etree.parse('dop_raboty_kopia.xml') | |
root = tree.getroot() | |
chapter = root.find('.//Chapters/Chapter') | |
position = chapter.getchildren()[1] | |
for i in range(len(a)): | |
new_position = copy.deepcopy(position) | |
quantity = new_position.find('Quantity') | |
quantity.attrib['Fx'] = str(b[i]) | |
new_position.attrib['Caption'] = a[i] | |
chapter.insert(len(chapter.getchildren()), new_position) | |
tree.write('output.xml', encoding="windows-1251") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment