{"id":331100,"date":"2022-03-26T21:00:07","date_gmt":"2022-03-26T21:00:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=331100"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=331100","title":{"rendered":"<span>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f\u00a0 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0440\u043e\u043a \u043d\u0430<br \/> <code>python<\/code>, \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432.<br \/> \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>difflib<\/code> \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439, \u043d\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0434\u043b\u044f \u043d\u0435\u0451 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433.<\/p>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/p>\n<pre><code class=\"python\">st1 = \"\"\"\/media\/user\/dd19b13d-bd85-46bb-8db9-5b8f6cf7a825\/MyProject\/PycharmProject\/testfull_pack\/venvs\/bin\/python\/scratch_34.py\"\"\" st2 = \"\"\"\/media\/user\/dd19b13d-bd85-46bb-8et9-5b8f6cf7a825\/MyProject\/PycharmProjects\/testfull_pack\/venvs\/bin\/python\/scratch_34.py\"\"\" rs = ''.join(list(difflib.unified_diff(st1, st2)))print(rs)<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442:<\/p>\n<pre><code>---  +++  @@ -30,8 +30,8 @@  b - 8-d-b+e+t 9 - 5@@ -71,6 +71,7 @@  e c t+s \/ t e<\/code><\/pre>\n<p>\u041c\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442<\/p>\n<pre><code class=\"python\">class colors:     green = '\\x1b[32m'     reset = '\\x1b[0m'     red = '\\x1b[31m'     black = '\\x1b[30m'     yellow = '\\x1b[33m'     blue = '\\x1b[34m'     magenta = '\\x1b[35m'     cyan = '\\x1b[36m'     white = '\\x1b[37m'     bg_red = '\\x1b[41m'     bg_green = '\\x1b[42m'   def diff_string(str1: str, str2: str):     _max = max([len(str1), len(str2)])      _len_str1 = len(str1)     _len_str2 = len(str2)     _res1 = ''     _res2 = ''      for _symbol in range(_max):          if _symbol &lt; _len_str1 and _symbol &lt; _len_str2:             if str1[_symbol] == str2[_symbol]:                 _res1 += '{1}{0}{2}'.format(str1[_symbol], colors.green, colors.reset)                 _res2 += '{1}{0}{2}'.format(str2[_symbol], colors.green, colors.reset)             else:                 _res1 += '{1}{0}{2}'.format(str1[_symbol], colors.red, colors.reset)                 _res2 += '{1}{0}{2}'.format(str2[_symbol], colors.red, colors.reset)                 continue          elif _symbol &lt; _len_str1:             _res1 += '{1}{0}{2}'.format(str1[_symbol], colors.bg_green, colors.reset)             _res2 += '{1}{0}{2}'.format(' ', colors.bg_red, colors.reset)         elif _symbol &lt; _len_str2:             _res1 += '{1}{0}{2}'.format(' ', colors.bg_red, colors.reset)             _res2 += '{1}{0}{2}'.format(str2[_symbol], colors.bg_green, colors.reset)          else:             raise ValueError      return _res1, _res2   if __name__ == '__main__':     st1 = \"\"\"\/media\/user\/dd19b13d-bd85-46bb-8db9-5b8f6cf7a825\/MyProject\/PycharmProject\/testfull_pack\/venvs\/bin\/python\/scratch_34.py\"\"\"     st2 = \"\"\"\/media\/user\/dd19b13d-bd85-46bb-8et9-5b8f6cf7a825\/MyProject\/PycharmProjects\/testfull_pack\/venvs\/bin\/python\/scratch_34.py\"\"\"      # \u041f\u0440\u0438\u043c\u0435\u0440 1     rst1, rst2 = diff_string(st1, st2)     print(f'str1:::\\n{rst1}')     print(f'str2:::\\n{rst2}')<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e85\/04f\/20d\/e8504f20d0042ad242d365f6d425eef9.png\" width=\"997\" height=\"99\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e85\/04f\/20d\/e8504f20d0042ad242d365f6d425eef9.png\"\/><figcaption><\/figcaption><\/figure>\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\/657609\/\"> https:\/\/habr.com\/ru\/post\/657609\/<\/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_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f\u00a0 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0440\u043e\u043a \u043d\u0430<br \/> <code>python<\/code>, \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432.<br \/> \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>difflib<\/code> \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439, \u043d\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0434\u043b\u044f \u043d\u0435\u0451 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433.<\/p>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/p>\n<pre><code class=\"python\">st1 = \"\"\"\/media\/user\/dd19b13d-bd85-46bb-8db9-5b8f6cf7a825\/MyProject\/PycharmProject\/testfull_pack\/venvs\/bin\/python\/scratch_34.py\"\"\" st2 = \"\"\"\/media\/user\/dd19b13d-bd85-46bb-8et9-5b8f6cf7a825\/MyProject\/PycharmProjects\/testfull_pack\/venvs\/bin\/python\/scratch_34.py\"\"\" rs = ''.join(list(difflib.unified_diff(st1, st2)))print(rs)<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442:<\/p>\n<pre><code>---  +++  @@ -30,8 +30,8 @@  b - 8-d-b+e+t 9 - 5@@ -71,6 +71,7 @@  e c t+s \/ t e<\/code><\/pre>\n<p>\u041c\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442<\/p>\n<pre><code class=\"python\">class colors:     green = '\\x1b[32m'     reset = '\\x1b[0m'     red = '\\x1b[31m'     black = '\\x1b[30m'     yellow = '\\x1b[33m'     blue = '\\x1b[34m'     magenta = '\\x1b[35m'     cyan = '\\x1b[36m'     white = '\\x1b[37m'     bg_red = '\\x1b[41m'     bg_green = '\\x1b[42m'   def diff_string(str1: str, str2: str):     _max = max([len(str1), len(str2)])      _len_str1 = len(str1)     _len_str2 = len(str2)     _res1 = ''     _res2 = ''      for _symbol in range(_max):          if _symbol &lt; _len_str1 and _symbol &lt; _len_str2:             if str1[_symbol] == str2[_symbol]:                 _res1 += '{1}{0}{2}'.format(str1[_symbol], colors.green, colors.reset)                 _res2 += '{1}{0}{2}'.format(str2[_symbol], colors.green, colors.reset)             else:                 _res1 += '{1}{0}{2}'.format(str1[_symbol], colors.red, colors.reset)                 _res2 += '{1}{0}{2}'.format(str2[_symbol], colors.red, colors.reset)                 continue          elif _symbol &lt; _len_str1:             _res1 += '{1}{0}{2}'.format(str1[_symbol], colors.bg_green, colors.reset)             _res2 += '{1}{0}{2}'.format(' ', colors.bg_red, colors.reset)         elif _symbol &lt; _len_str2:             _res1 += '{1}{0}{2}'.format(' ', colors.bg_red, colors.reset)             _res2 += '{1}{0}{2}'.format(str2[_symbol], colors.bg_green, colors.reset)          else:             raise ValueError      return _res1, _res2   if __name__ == '__main__':     st1 = \"\"\"\/media\/user\/dd19b13d-bd85-46bb-8db9-5b8f6cf7a825\/MyProject\/PycharmProject\/testfull_pack\/venvs\/bin\/python\/scratch_34.py\"\"\"     st2 = \"\"\"\/media\/user\/dd19b13d-bd85-46bb-8et9-5b8f6cf7a825\/MyProject\/PycharmProjects\/testfull_pack\/venvs\/bin\/python\/scratch_34.py\"\"\"      # \u041f\u0440\u0438\u043c\u0435\u0440 1     rst1, rst2 = diff_string(st1, st2)     print(f'str1:::\\n{rst1}')     print(f'str2:::\\n{rst2}')<\/code><\/pre>\n<p>\u041e\u0442\u0432\u0435\u0442:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\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\/657609\/\"> https:\/\/habr.com\/ru\/post\/657609\/<\/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-331100","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331100","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=331100"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331100\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=331100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=331100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=331100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}