{"id":341356,"date":"2022-11-17T15:00:15","date_gmt":"2022-11-17T15:00:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341356"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341356","title":{"rendered":"<span>\u0421\u0442\u0430\u0440\u0442\u0443\u0435\u043c \u0438\u0437 1\u0421 \u0432 Python<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 2022 \u043c\u043e\u0434\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0432 Python. \u042f \u043d\u0435 \u0433\u043e\u043d\u044f\u044e\u0441\u044c \u0437\u0430 \u043c\u043e\u0434\u043e\u0439, \u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430. \u041a\u043b\u0438\u0435\u043d\u0442 \u0445\u043e\u0442\u0435\u043b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c XML \u0444\u0430\u0439\u043b, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 \u00ab\u041c\u043e\u0439 \u0441\u043a\u043b\u0430\u0434\u00bb \u2014 \u0443\u0431\u0440\u0430\u0442\u044c \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0435 \u043d\u0443\u043b\u0438 \u0432 \u0442\u0435\u0433\u0430\u0445\u00a0<em>\u041a\u043e\u0434\u0422\u043e\u0432<\/em>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e54\/205\/393\/e542053935e054c4c8a75249d72e57bb.png\" alt=\"\" title=\"\" width=\"1024\" height=\"382\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e54\/205\/393\/e542053935e054c4c8a75249d72e57bb.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u042f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u0431\u0443\u0445\u0433\u0430\u043b\u0442\u0435\u0440\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e 1\u0421, \u043d\u0443 \u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b \u043c\u0435\u043d\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u044d\u0442\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0432 1\u0421, \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432 1\u0421:\u0414\u0435\u043d\u044c\u0433\u0438.<\/p>\n<p>\u042f \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u043b\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0434\u0443\u043c\u0430\u043b \u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 VBS. \u041d\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 Mac, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u0435\u043d \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u044b\u0439 \u044f\u0437\u044b\u043a. \u0412\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 Python.<\/p>\n<p>\u042f \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b\u00a0<a href=\"https:\/\/forum.mista.ru\/topic.php?id=883353\" rel=\"noopener noreferrer nofollow\"><u>\u043f\u043e\u043c\u043e\u0449\u0438<\/u><\/a>\u00a0\u043d\u0430 \u041c\u0438\u0441\u0442\u0435 \u0438 \u043c\u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c PY-\u0441\u043a\u0440\u0438\u043f\u0442.<\/p>\n<p>\u042f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u041f\u0438\u0442\u043e\u043d, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e\u00a0<a href=\"https:\/\/pythonchik.ru\/osnovy\/ustanovka-python--windows-linux-mac-os\" rel=\"noopener noreferrer nofollow\"><u>\u0437\u0434\u0435\u0441\u044c<\/u><\/a>.<\/p>\n<p>\u041f\u043e\u0447\u0438\u0442\u0430\u043b \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443\u00a0<a href=\"https:\/\/all-python.ru\/osnovy\/kak-zapustit-skript.html\" rel=\"noopener noreferrer nofollow\"><u>\u0437\u0434\u0435\u0441\u044c<\/u><\/a>.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u041f\u0438\u0442\u043e\u043d \u0438 \u0432\u0432\u0435\u043b \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a67\/774\/bbb\/a67774bbbfa0aed3f307b75e66e47917.png\" alt=\"\" title=\"\" width=\"570\" height=\"176\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a67\/774\/bbb\/a67774bbbfa0aed3f307b75e66e47917.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0433\u043d\u0430\u043b Hello World:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e56\/6d9\/57c\/e566d957c20ec1925d3841ca155be615.png\" alt=\"\" title=\"\" width=\"244\" height=\"94\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e56\/6d9\/57c\/e566d957c20ec1925d3841ca155be615.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f68\/c37\/042\/f68c37042774781e5e677210502eb1ca.png\" alt=\"\" title=\"\" width=\"292\" height=\"109\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f68\/c37\/042\/f68c37042774781e5e677210502eb1ca.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443 \u0438 \u0434\u0430\u043b\u0435\u0435 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u041c\u0438\u0441\u0442\u044b \u0432 \u0444\u0430\u0439\u043b upd_xml.py.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0435\u0433\u043e \u0432 IDE:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/49e\/921\/b5c\/49e921b5c9c4e45a5a78d63a6dd9f7f3.png\" alt=\"\" title=\"\" width=\"657\" height=\"115\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/49e\/921\/b5c\/49e921b5c9c4e45a5a78d63a6dd9f7f3.png\"\/><figcaption><\/figcaption><\/figure>\n<p>IDE \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432 UTF, \u043f\u0435\u0440\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043b \u0440\u0443\u043a\u0430\u043c\u0438 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b \u0438\u0437 \u0431\u043b\u043e\u043a\u043d\u043e\u0442\u0430 \u0442\u0435\u043a\u0441\u0442 \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u043b \u0432 IDE.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b\u0434\u0430\u043b \u043f\u0435\u0440\u0432\u044b\u0435 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/208\/43a\/e4e\/20843ae4e01677b6fe08526e93d1878c.png\" alt=\"\" title=\"\" width=\"673\" height=\"455\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/208\/43a\/e4e\/20843ae4e01677b6fe08526e93d1878c.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/def\/b16\/cab\/defb16cabdb34db0e75d3f74936b4562.png\" alt=\"\" title=\"\" width=\"702\" height=\"343\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/def\/b16\/cab\/defb16cabdb34db0e75d3f74936b4562.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0433\u0443\u0433\u043b\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435, \u043d\u0430\u0448\u0435\u043b\u00a0<a href=\"https:\/\/tonais.ru\/file\/rabota-xml-python-elementtree\" rel=\"noopener noreferrer nofollow\"><u>\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0443\u0442<\/u><\/a>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b, \u0447\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u0443 \u043c\u0435\u043d\u044f \u0442\u043e\u0436\u0435 \u0442\u0430\u043a. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b XML\u00a0<a href=\"https:\/\/codebeautify.org\/xmlvalidator\" rel=\"noopener noreferrer nofollow\"><u>\u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u043c<\/u><\/a>\u00a0\u0438 \u043d\u0430\u0448\u0435\u043b \u043e\u0448\u0438\u0431\u043a\u0443 \u2014 \u0432\u0435\u0434\u044c \u044f XML \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0440\u0443\u043a\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4a9\/78a\/71e\/4a978a71e9592bec5842b2a8d5319b49.png\" alt=\"\" title=\"\" width=\"1024\" height=\"546\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4a9\/78a\/71e\/4a978a71e9592bec5842b2a8d5319b49.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a XML \u0441\u0442\u0430\u043b \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c, \u0441\u0442\u0430\u043b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0bd\/f7a\/d9a\/0bdf7ad9a7cf92d1616c743c9a8dbb9f.png\" alt=\"\" title=\"\" width=\"702\" height=\"454\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0bd\/f7a\/d9a\/0bdf7ad9a7cf92d1616c743c9a8dbb9f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0433\u0443\u0433\u043b\u0438\u043b \u00ab<em>cannot use absolute path on element keyerror<\/em>\u00ab, \u043d\u0430\u0448\u0435\u043b\u00a0<a href=\"https:\/\/stackoverflow.com\/questions\/5501118\/python-elementtree-cannot-use-absolute-path-on-element\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/u><\/a>, \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0434\u043b\u044f\u00a0<em>findall<\/em>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/113\/37f\/627\/11337f6272987c45a2f89d00eca893f1.png\" alt=\"\" title=\"\" width=\"671\" height=\"457\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/113\/37f\/627\/11337f6272987c45a2f89d00eca893f1.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0424\u0430\u0439\u043b \u0441\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e. \u041d\u0430 \u041c\u0438\u0441\u0442\u0435 \u043c\u043d\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u0430\u043b\u0438, \u043a\u0430\u043a \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0434\u0438\u0430\u043b\u043e\u0433 \u0432\u0432\u043e\u0434\u0430 \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u043d\u044f\u043b\u043e 40 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0435\u0449\u0435 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0432 \u0444\u0430\u0439\u043b \u0441 \u043f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u043e\u0439 prev_, \u0430 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 XML. \u041d\u0430 \u044d\u0442\u043e \u0443\u0448\u043b\u043e \u0435\u0449\u0435 10 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u0437\u0430 \u0447\u0430\u0441 1\u0441-\u043d\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u043d\u044c\u0448\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u043f\u0438\u0442\u043e\u043d\u043e\u043c, \u0441\u043c\u043e\u0433 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 Python. \u041d\u0435 \u0431\u043e\u0433\u0438 \u0433\u043e\u0440\u0448\u043a\u0438 \u043e\u0431\u0436\u0438\u0433\u0430\u044e\u0442.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/python \u00a0 \u00a0 import os import sys import xml.etree.ElementTree as ET import ctypes  # An included library with Python install. def Mbox(title, text, style):     return ctypes.windll.user32.MessageBoxW(0, text, title, style) \u00a0 from tkinter import filedialog as FD \u00a0 filename = None \u00a0 if len(sys.argv) > 1:     filename = sys.argv[1] \u00a0 if not filename:     filename = FD.askopenfilename(filetypes=[(\"xml files\",\"*.xml\")]) \u00a0 if not filename:     exit() \u00a0 tree = ET.parse(filename) root = tree.getroot() \u00a0 for node in root.findall(\".\/\/\u0414\u043e\u043f\u0421\u0432\u0435\u0434\u0422\u043e\u0432[@\u041a\u043e\u0434\u0422\u043e\u0432]\"): \u00a0     code = node.attrib['\u041a\u043e\u0434\u0422\u043e\u0432']     node.attrib['\u041a\u043e\u0434\u0422\u043e\u0432'] = code.lstrip('0') #\u0437\u0434\u0435\u0441\u044c \u043c\u0435\u043d\u044f\u0435\u043c \u043a\u043e\u0434 \u00a0 \u00a0 filename = os.path.abspath(filename) \u00a0 directory = os.path.dirname(filename) filename = os.path.basename(filename) \u00a0 os.rename(os.path.join(directory, filename), os.path.join(directory, \"src_\" + filename)) tree.write(os.path.join(directory, filename), encoding=\"windows-1251\") \u00a0 Mbox('\u0423\u0441\u043f\u0435\u0448\u043d\u043e', '\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 XML \u0444\u0430\u0439\u043b\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430', 1) \u00a0<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u041c\u0430\u043a\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/65c\/11f\/037\/65c11f037162cd99e12c15d64748e571.png\" alt=\"\" title=\"\" width=\"750\" height=\"422\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/65c\/11f\/037\/65c11f037162cd99e12c15d64748e571.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/700020\/\"> https:\/\/habr.com\/ru\/post\/700020\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 2022 \u043c\u043e\u0434\u043d\u043e \u0443\u043c\u0435\u0442\u044c \u0432 Python. \u042f \u043d\u0435 \u0433\u043e\u043d\u044f\u044e\u0441\u044c \u0437\u0430 \u043c\u043e\u0434\u043e\u0439, \u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430. \u041a\u043b\u0438\u0435\u043d\u0442 \u0445\u043e\u0442\u0435\u043b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c XML \u0444\u0430\u0439\u043b, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 \u00ab\u041c\u043e\u0439 \u0441\u043a\u043b\u0430\u0434\u00bb \u2014 \u0443\u0431\u0440\u0430\u0442\u044c \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0435 \u043d\u0443\u043b\u0438 \u0432 \u0442\u0435\u0433\u0430\u0445\u00a0<em>\u041a\u043e\u0434\u0422\u043e\u0432<\/em>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u042f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u0431\u0443\u0445\u0433\u0430\u043b\u0442\u0435\u0440\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u043e 1\u0421, \u043d\u0443 \u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b \u043c\u0435\u043d\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u044d\u0442\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0432 1\u0421, \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432 1\u0421:\u0414\u0435\u043d\u044c\u0433\u0438.<\/p>\n<p>\u042f \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u043b\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0434\u0443\u043c\u0430\u043b \u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 VBS. \u041d\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 Mac, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u0435\u043d \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432\u044b\u0439 \u044f\u0437\u044b\u043a. \u0412\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 Python.<\/p>\n<p>\u042f \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b\u00a0<a href=\"https:\/\/forum.mista.ru\/topic.php?id=883353\" rel=\"noopener noreferrer nofollow\"><u>\u043f\u043e\u043c\u043e\u0449\u0438<\/u><\/a>\u00a0\u043d\u0430 \u041c\u0438\u0441\u0442\u0435 \u0438 \u043c\u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c PY-\u0441\u043a\u0440\u0438\u043f\u0442.<\/p>\n<p>\u042f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u041f\u0438\u0442\u043e\u043d, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e\u00a0<a href=\"https:\/\/pythonchik.ru\/osnovy\/ustanovka-python--windows-linux-mac-os\" rel=\"noopener noreferrer nofollow\"><u>\u0437\u0434\u0435\u0441\u044c<\/u><\/a>.<\/p>\n<p>\u041f\u043e\u0447\u0438\u0442\u0430\u043b \u043a\u0430\u043a \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443\u00a0<a href=\"https:\/\/all-python.ru\/osnovy\/kak-zapustit-skript.html\" rel=\"noopener noreferrer nofollow\"><u>\u0437\u0434\u0435\u0441\u044c<\/u><\/a>.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u041f\u0438\u0442\u043e\u043d \u0438 \u0432\u0432\u0435\u043b \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0433\u043d\u0430\u043b Hello World:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443 \u0438 \u0434\u0430\u043b\u0435\u0435 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043a\u0440\u0438\u043f\u0442 \u0441 \u041c\u0438\u0441\u0442\u044b \u0432 \u0444\u0430\u0439\u043b upd_xml.py.<\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0435\u0433\u043e \u0432 IDE:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>IDE \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432 UTF, \u043f\u0435\u0440\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043b \u0440\u0443\u043a\u0430\u043c\u0438 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b \u0438\u0437 \u0431\u043b\u043e\u043a\u043d\u043e\u0442\u0430 \u0442\u0435\u043a\u0441\u0442 \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u043b \u0432 IDE.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b\u0434\u0430\u043b \u043f\u0435\u0440\u0432\u044b\u0435 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0433\u0443\u0433\u043b\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435, \u043d\u0430\u0448\u0435\u043b\u00a0<a href=\"https:\/\/tonais.ru\/file\/rabota-xml-python-elementtree\" rel=\"noopener noreferrer nofollow\"><u>\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0443\u0442<\/u><\/a>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b, \u0447\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u0443 \u043c\u0435\u043d\u044f \u0442\u043e\u0436\u0435 \u0442\u0430\u043a. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b XML\u00a0<a href=\"https:\/\/codebeautify.org\/xmlvalidator\" rel=\"noopener noreferrer nofollow\"><u>\u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u043c<\/u><\/a>\u00a0\u0438 \u043d\u0430\u0448\u0435\u043b \u043e\u0448\u0438\u0431\u043a\u0443 \u2014 \u0432\u0435\u0434\u044c \u044f XML \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0440\u0443\u043a\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a XML \u0441\u0442\u0430\u043b \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c, \u0441\u0442\u0430\u043b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0433\u0443\u0433\u043b\u0438\u043b \u00ab<em>cannot use absolute path on element keyerror<\/em>\u00ab, \u043d\u0430\u0448\u0435\u043b\u00a0<a href=\"https:\/\/stackoverflow.com\/questions\/5501118\/python-elementtree-cannot-use-absolute-path-on-element\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/u><\/a>, \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0434\u043b\u044f\u00a0<em>findall<\/em>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0424\u0430\u0439\u043b \u0441\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e. \u041d\u0430 \u041c\u0438\u0441\u0442\u0435 \u043c\u043d\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u0430\u043b\u0438, \u043a\u0430\u043a \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0434\u0438\u0430\u043b\u043e\u0433 \u0432\u0432\u043e\u0434\u0430 \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u043d\u044f\u043b\u043e 40 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0435\u0449\u0435 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0432 \u0444\u0430\u0439\u043b \u0441 \u043f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u043e\u0439 prev_, \u0430 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 XML. \u041d\u0430 \u044d\u0442\u043e \u0443\u0448\u043b\u043e \u0435\u0449\u0435 10 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u0437\u0430 \u0447\u0430\u0441 1\u0441-\u043d\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u043d\u044c\u0448\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u043f\u0438\u0442\u043e\u043d\u043e\u043c, \u0441\u043c\u043e\u0433 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 Python. \u041d\u0435 \u0431\u043e\u0433\u0438 \u0433\u043e\u0440\u0448\u043a\u0438 \u043e\u0431\u0436\u0438\u0433\u0430\u044e\u0442.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/python \u00a0 \u00a0 import os import sys import xml.etree.ElementTree as ET import ctypes  # An included library with Python install. def Mbox(title, text, style):     return ctypes.windll.user32.MessageBoxW(0, text, title, style) \u00a0 from tkinter import filedialog as FD \u00a0 filename = None \u00a0 if len(sys.argv) > 1:     filename = sys.argv[1] \u00a0 if not filename:     filename = FD.askopenfilename(filetypes=[(\"xml files\",\"*.xml\")]) \u00a0 if not filename:     exit() \u00a0 tree = ET.parse(filename) root = tree.getroot() \u00a0 for node in root.findall(\".\/\/\u0414\u043e\u043f\u0421\u0432\u0435\u0434\u0422\u043e\u0432[@\u041a\u043e\u0434\u0422\u043e\u0432]\"): \u00a0     code = node.attrib['\u041a\u043e\u0434\u0422\u043e\u0432']     node.attrib['\u041a\u043e\u0434\u0422\u043e\u0432'] = code.lstrip('0') #\u0437\u0434\u0435\u0441\u044c \u043c\u0435\u043d\u044f\u0435\u043c \u043a\u043e\u0434 \u00a0 \u00a0 filename = os.path.abspath(filename) \u00a0 directory = os.path.dirname(filename) filename = os.path.basename(filename) \u00a0 os.rename(os.path.join(directory, filename), os.path.join(directory, \"src_\" + filename)) tree.write(os.path.join(directory, filename), encoding=\"windows-1251\") \u00a0 Mbox('\u0423\u0441\u043f\u0435\u0448\u043d\u043e', '\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 XML \u0444\u0430\u0439\u043b\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430', 1) \u00a0<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u041c\u0430\u043a\u0435.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/700020\/\"> https:\/\/habr.com\/ru\/post\/700020\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-341356","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=341356"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341356\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}