{"id":295443,"date":"2019-12-17T16:15:48","date_gmt":"2019-12-17T16:15:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=295443"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=295443","title":{"rendered":"\u041f\u043e\u0434\u0431\u043e\u0440\u043a\u0430 @pythonetc, \u043d\u043e\u044f\u0431\u0440\u044c 2019"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/480138\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ft\/mv\/ba\/ftmvbae7hzixblb4z2x7ur8nwgg.jpeg\"><\/div>\n<p>  \u041d\u043e\u0432\u0430\u044f \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0430 \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u043f\u0440\u043e Python \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0437 \u043c\u043e\u0435\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 @pythonetc.<\/p>\n<p>  \u2190<a href=\"https:\/\/habr.com\/en\/search\/?q=pythonetc#h\"> Previous publications<\/a><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/208\/1cc\/1fa\/2081cc1fa6dbebbbb6ddd4108512ff5b.png\"><\/div>\n<p>  <code>PATH<\/code> \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043f\u0443\u0442\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0449\u0443\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0444\u0430\u0439\u043b\u044b. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <code>ls<\/code>, \u043e\u043d\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0449\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b <code>ls<\/code> \u043f\u043e \u0432\u0441\u0435\u043c \u043f\u0443\u0442\u044f\u043c, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u0432 <code>PATH<\/code>.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"python\">$ echo $PATH \/usr\/local\/bin:\/usr\/bin:\/usr\/local\/sbin:\/usr\/sbin:\/home\/v.pushtaev\/.local\/bin:\/home\/v.pushtaev\/bin $ which ls \/usr\/bin\/ls<\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0443\u0442\u0438 \u0432 <code>PATH<\/code> \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>:<\/code>. \u041f\u0443\u0442\u0430\u043d\u0438\u0446\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442: \u0435\u0441\u043b\u0438 \u043f\u0443\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <code>:<\/code>, \u0442\u043e \u043e\u043d \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 <code>PATH<\/code>.<\/p>\n<p>  \u041d\u043e \u044d\u0442\u043e \u0432\u0435\u0440\u043d\u043e \u043d\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u0412 Python \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0439 \u041e\u0421 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>os.pathsep<\/code>:<\/p>\n<pre><code class=\"python\">Python 3.5.0 [...] on win32 Type \"help\", \"copyright\", \"credits\" or \"license\" for more information. &gt;&gt;&gt; import os &gt;&gt;&gt; os.pathsep ';'<\/code><\/pre>\n<p>  \u041d\u0435 \u043f\u0443\u0442\u0430\u0439\u0442\u0435 <code>os.pathsep<\/code> \u0441 <code>os.path.sep<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u043c \u0434\u043b\u044f \u043f\u0443\u0442\u0435\u0439 \u043a \u0444\u0430\u0439\u043b\u0430\u043c:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; os.path.sep '\/'<\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/208\/1cc\/1fa\/2081cc1fa6dbebbbb6ddd4108512ff5b.png\"><\/div>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043b\u0435\u0433\u0447\u0435 \u0431\u044b\u043b\u043e \u0447\u0438\u0442\u0430\u0442\u044c, \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u043b\u0430\u0433 <code>re.VERBOSE<\/code>. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u044b \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0445\u043e\u0442\u0438\u0442\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 <code>#<\/code>:<\/p>\n<pre><code class=\"python\">import re  URL_RE = re.compile(r'''     ^     (https?):\/\/     (www[.])?     (     (?: [^.]+[.] )+     (   [^\/]+    )  # TLD     )     (\/.*)     $ ''', re.VERBOSE)  m = URL_RE.match('https:\/\/www.pythonetc.com\/about\/') schema, www, domain, tld, path = m.groups()  has_www: bool = bool(www)  print(f'schema={schema}, has_www={has_www}') print(f'domain={domain}, tld={tld}') print(f'path={path}') <\/code><\/pre>\n<p>  <code>re.X<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u043e\u043c \u0434\u043b\u044f <code>re.VERBOSE<\/code>.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/208\/1cc\/1fa\/2081cc1fa6dbebbbb6ddd4108512ff5b.png\"><\/div>\n<p>  <code>complex<\/code> \u2014 \u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 Python \u0442\u0438\u043f \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; complex(1, 2).real 1.0 &gt;&gt;&gt; abs(complex(3, 4)) 5.0 &gt;&gt;&gt; complex(1, 2) == complex(1, -2).conjugate() True &gt;&gt;&gt; str(complex(2, -3)) '(2-3j)'<\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 Python \u0435\u0441\u0442\u044c \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; (3 + 4j).imag 4.0 &gt;&gt;&gt; not (3 + 4j) False &gt;&gt;&gt; (-3 - 4j) + (2 - 2j) (-1-6j)<\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/208\/1cc\/1fa\/2081cc1fa6dbebbbb6ddd4108512ff5b.png\"><\/div>\n<p>  \u041d\u043e\u0442\u0430\u0446\u0438\u044e <code>a : b : c<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <code>slice(a, b, c)<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0434\u043d\u0438\u0445 \u043b\u0438\u0448\u044c \u0441\u043a\u043e\u0431\u043e\u043a:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; [1, 2, 3, 4, 5][0:4:2] [1, 3] &gt;&gt;&gt; [1, 2, 3, 4, 5][slice(0, 4, 2)] [1, 3]<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 slice-\u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0442\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">def multislice(slc, *iterables):     return [i[slc] for i in iterables]   print(multislice(     slice(2, 6, 2),     [1, 2, 3, 4, 5, 6, 7],     [2, 4, 2, 4, 2, 4, 2], ))<\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <code>[a : b : c]<\/code>:<\/p>\n<pre><code class=\"python\">from functools import partial   class SliceArgDecorator:     def __init__(self, f):         self._f = f      def __getitem__(self, slc):         return partial(self._f, slc)  slice_arg = SliceArgDecorator   @slice_arg def multislice(slc, *iterables):     return [i[slc] for i in iterables]   print(multislice[2:6:2](     [1, 2, 3, 4, 5, 6, 7],     [2, 4, 2, 4, 2, 4, 2], ))<\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/208\/1cc\/1fa\/2081cc1fa6dbebbbb6ddd4108512ff5b.png\"><\/div>\n<p>  <code>__getattribute__<\/code> \u2014 \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0443\u043c\u0435\u0441\u0442\u043d\u043e. \u0422\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441 \u043d\u0435\u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c:<\/p>\n<pre><code class=\"python\">class CustomEq:     def __init__(self, orig, *, key):         self._orig = orig         self._key = key      def __lt__(self, other):         return self._key(self) &lt; self._key(other)      def __getattribute__(self, name):         if name in {'_key', '_orig', '__lt__'}:             return super().__getattribute__(name)          return getattr(self._orig, name)  class User:     def __init__(self, user_id):         self._user_id = user_id      def get_user_id(self):         return self._user_id   def comparable(obj, *, key):     return CustomEq(obj, key=key)   user1 = comparable(User(1), key=lambda u: u.get_user_id()) user2 = comparable(User(2), key=lambda u: u.get_user_id())  print(user2 &gt; user1)  # True print(user2 &lt; user1)  # False print(user2.get_user_id())  # 2 <\/code><\/pre>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <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\/company\/mailru\/blog\/480138\/\"> https:\/\/habr.com\/ru\/company\/mailru\/blog\/480138\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/mailru\/blog\/480138\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ft\/mv\/ba\/ftmvbae7hzixblb4z2x7ur8nwgg.jpeg\"><\/div>\n<p>  \u041d\u043e\u0432\u0430\u044f \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0430 \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u043f\u0440\u043e Python \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0437 \u043c\u043e\u0435\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 @pythonetc.<\/p>\n<p>  \u2190<a href=\"https:\/\/habr.com\/en\/search\/?q=pythonetc#h\"> Previous publications<\/a><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/208\/1cc\/1fa\/2081cc1fa6dbebbbb6ddd4108512ff5b.png\"><\/div>\n<p>  <code>PATH<\/code> \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043f\u0443\u0442\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0449\u0443\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0444\u0430\u0439\u043b\u044b. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <code>ls<\/code>, \u043e\u043d\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0449\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b <code>ls<\/code> \u043f\u043e \u0432\u0441\u0435\u043c \u043f\u0443\u0442\u044f\u043c, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u0432 <code>PATH<\/code>.  <\/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-295443","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295443","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=295443"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295443\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}