{"id":312891,"date":"2020-11-10T15:00:26","date_gmt":"2020-11-10T15:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=312891"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=312891","title":{"rendered":"\u041c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u0432 Python"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p><em>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <\/em><a href=\"https:\/\/otus.pw\/NAGBG\/\"><em>&#171;<\/em><strong><em>Python Developer. Basic&#187;<\/em><\/strong><\/a><strong>.<\/strong><\/p>\n<\/blockquote>\n<hr>\n<p>\u041c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u2013 \u044d\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438. \u041f\u043e\u0434\u043e\u0431\u043d\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u00ab\u043e\u0431\u044b\u0447\u043d\u044b\u0439\u00bb \u043a\u043b\u0430\u0441\u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430, \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432.<\/p>\n<p>\u041c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0432\u0441\u0435\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u044f\u0437\u044b\u043a\u0430\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0422\u0435 \u044f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0445 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442, \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u043e \u0432 Python \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u0435\u0441\u0442\u044c.<\/p>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u0432 Python \u043a\u0430\u043a \u00ab\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0436\u0434\u0443\u0442 \u0438\u043b\u0438 \u0438\u0449\u0443\u0442 \u0437\u0430\u0434\u0430\u0447\u0443\u00bb.<\/p>\n<p>\u0423 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u0412\u044b\u0434\u0435\u043b\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043d\u0438\u0445:<\/p>\n<ul>\n<li>\n<p>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043a\u0441\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\/\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h3>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0432 Python, \u043d\u043e \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f \u043e\u0442 \u00ab\u0442\u0438\u043f\u0430\u00bb. \u0415\u0449\u0435 \u043e\u0434\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>metaclass<\/code> \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 (\u043e\u0434\u043d\u0430\u043a\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0431\u044b\u0442\u044c), \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d <code>type()<\/code> (\u0442.\u0435. <code>_call_<\/code> \u0442\u0438\u043f\u0430). \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>metaclass<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0442\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0435\u043c\u0443 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u043e <code>type<\/code>.<\/p>\n<p>    \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441. \u041e\u043d \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0443\u043c\u0435\u0435\u0442, \u043a\u0440\u043e\u043c\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0441\u0432\u043e\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435<code>_new_<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 <code>type._new_<\/code>:<\/p>\n<pre><code class=\"python\">class LittleMeta(type):     def __new__(cls, clsname, superclasses, attributedict):         print(\"clsname: \", clsname)         print(\"superclasses: \", superclasses)         print(\"attributedict: \", attributedict)         return type.__new__(cls, clsname, superclasses, attributedict)<\/code><\/pre>\n<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 <em>LittleMeta<\/em> \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<pre><code class=\"python\">class S:     pass   class A(S, metaclass=LittleMeta):     pass   a = A()<\/code><\/pre>\n<pre><code>clsname:  A superclasses:  (&amp;lt;class '__main__.S'&gt;,) attributedict:  {'__module__': '__main__', '__qualname__': 'A'}<\/code><\/pre>\n<\/p>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d <code>LittleMeta._new_<\/code>, \u0430 \u043d\u0435 <code>type._new_<\/code>.&nbsp;<\/p>\n<p> \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 <code>EssentialAnswers<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 <code>augmen_tanswer<\/code>:&nbsp;<\/p>\n<pre><code class=\"python\"> x = input(\"Do you need the answer? (y\/n): \") if x.lower() == \"y\":     required = True else:     required = False       def the_answer(self, *args):                       return 42       class EssentialAnswers(type):          def __init__(cls, clsname, superclasses, attributedict):         if required:             cls.the_answer = the_answer                                  class Philosopher1(metaclass=EssentialAnswers):      pass   class Philosopher2(metaclass=EssentialAnswers):      pass   class Philosopher3(metaclass=EssentialAnswers):      pass           plato = Philosopher1() print(plato.the_answer())   kant = Philosopher2() # let's see what Kant has to say :-) print(kant.the_answer())<\/code><\/pre>\n<pre><code>Do you need the answer? (y\/n): y 42 42<\/code><\/pre>\n<p>  \u0412 \u0433\u043b\u0430\u0432\u0435 \u00abType and Class Relationship\u00bb \u043c\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Python \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442:<\/p>\n<pre><code class=\"python\">type(classname, superclasses, attributes_dict)<\/code><\/pre>\n<\/p>\n<p> \u041d\u043e \u043d\u0435 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 \u0431\u044b\u043b \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u043c\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435. \u041d\u0430\u0448\u0438 \u043a\u043b\u0430\u0441\u0441\u044b <em>Philosopher1<\/em>, <em>Philosopher2<\/em> \u0438 <em>Philosopher3<\/em> \u0431\u044b\u043b\u0438 \u00ab\u043f\u0440\u0438\u0446\u0435\u043f\u043b\u0435\u043d\u044b\u00bb \u043a \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u0443 <em>EssentialAnswers<\/em>. \u0418 \u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 <em>EssentialAnswers<\/em> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0432\u043c\u0435\u0441\u0442\u043e <em>type<\/em>:<\/p>\n<pre><code class=\"python\">EssentialAnswer(classname, superclasses, attributes_dict)<\/code><\/pre>\n<\/p>\n<p> \u0415\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u043c, \u0442\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">EssentialAnswer('Philopsopher1',                  (),                  {'__module__': '__main__', '__qualname__': 'Philosopher1'})<\/code><\/pre>\n<p>    \u0414\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b <em>Philosopher<\/em> \u0431\u0443\u0434\u0443\u0442 \u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h3>\n<\/p>\n<p><strong>    <\/strong>\u0421\u0438\u043d\u0433\u043b\u0442\u043e\u043d&nbsp; &#8212; \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u0435\u043d \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442. \u041f\u043e\u043d\u044f\u0442\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0438\u043b\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c. \u0421\u0430\u043c \u0442\u0435\u0440\u043c\u0438\u043d \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u043d\u0430\u043c \u0438\u0437 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438, \u0433\u0434\u0435 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d, \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0441 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c.<\/p>\n<pre><code class=\"python\">class Singleton(type):     _instances = {}     def __call__(cls, *args, **kwargs):         if cls not in cls._instances:             cls._instances[cls] = super(Singleton,                                      cls).__call__(*args, **kwargs)         return cls._instances[cls]           class SingletonClass(metaclass=Singleton):     pass   class RegularClass():     pass   x = SingletonClass() y = SingletonClass() print(x == y)   x = RegularClass() y = RegularClass() print(x == y)<\/code><\/pre>\n<pre><code>True False<\/code><\/pre>\n<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c Singleton-\u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f\u0441\u044c \u043e\u0442 <em>Singleton<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">class Singleton(object):     _instance = None     def __new__(cls, *args, **kwargs):         if not cls._instance:             cls._instance = object.__new__(cls, *args, **kwargs)         return cls._instance       class SingletonClass(Singleton):     pass  class RegularClass():     pass   x = SingletonClass() y = SingletonClass() print(x == y)   x = RegularClass() y = RegularClass() print(x == y)<\/code><\/pre>\n<pre><code>True False<\/code><\/pre>\n<hr>\n<p><a href=\"https:\/\/otus.pw\/NAGBG\/\"><strong>\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0443\u0440\u0441\u0435.<\/strong><\/a><\/p>\n<hr>\n<h3>\u0427\u0438\u0442\u0430\u0442\u044c \u0435\u0449\u0451:<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/511840\/\">\u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FastAPI \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/510350\/\">\u0412 \u043a\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043a\u0438 \u0432 Python<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/509328\/\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 Python<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<p> \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\/otus\/blog\/527384\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/527384\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p><em>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <\/em><a href=\"https:\/\/otus.pw\/NAGBG\/\"><em>&#171;<\/em><strong><em>Python Developer. Basic&#187;<\/em><\/strong><\/a><strong>.<\/strong><\/p>\n<\/blockquote>\n<hr>\n<p>\u041c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u2013 \u044d\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438. \u041f\u043e\u0434\u043e\u0431\u043d\u043e \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u00ab\u043e\u0431\u044b\u0447\u043d\u044b\u0439\u00bb \u043a\u043b\u0430\u0441\u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430, \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432.<\/p>\n<p>\u041c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0432\u0441\u0435\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u044f\u0437\u044b\u043a\u0430\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0422\u0435 \u044f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0445 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442, \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u043e \u0432 Python \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u0435\u0441\u0442\u044c.<\/p>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u0432 Python \u043a\u0430\u043a \u00ab\u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0436\u0434\u0443\u0442 \u0438\u043b\u0438 \u0438\u0449\u0443\u0442 \u0437\u0430\u0434\u0430\u0447\u0443\u00bb.<\/p>\n<p>\u0423 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u0412\u044b\u0434\u0435\u043b\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043d\u0438\u0445:<\/p>\n<ul>\n<li>\n<p>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435;<\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u043a\u0441\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\/\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h3>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0432 Python, \u043d\u043e \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f \u043e\u0442 \u00ab\u0442\u0438\u043f\u0430\u00bb. \u0415\u0449\u0435 \u043e\u0434\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>metaclass<\/code> \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 (\u043e\u0434\u043d\u0430\u043a\u043e \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0431\u044b\u0442\u044c), \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d <code>type()<\/code> (\u0442.\u0435. <code>_call_<\/code> \u0442\u0438\u043f\u0430). \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>metaclass<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0442\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0435\u043c\u0443 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u043e <code>type<\/code>.<\/p>\n<p>    \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441. \u041e\u043d \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0443\u043c\u0435\u0435\u0442, \u043a\u0440\u043e\u043c\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0441\u0432\u043e\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435<code>_new_<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 <code>type._new_<\/code>:<\/p>\n<pre><code class=\"python\">class LittleMeta(type):     def __new__(cls, clsname, superclasses, attributedict):         print(\"clsname: \", clsname)         print(\"superclasses: \", superclasses)         print(\"attributedict: \", attributedict)         return type.__new__(cls, clsname, superclasses, attributedict)<\/code><\/pre>\n<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 <em>LittleMeta<\/em> \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<pre><code class=\"python\">class S:     pass   class A(S, metaclass=LittleMeta):     pass   a = A()<\/code><\/pre>\n<pre><code>clsname:  A superclasses:  (&amp;lt;class '__main__.S'&gt;,) attributedict:  {'__module__': '__main__', '__qualname__': 'A'}<\/code><\/pre>\n<\/p>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0431\u044b\u043b \u0432\u044b\u0437\u0432\u0430\u043d <code>LittleMeta._new_<\/code>, \u0430 \u043d\u0435 <code>type._new_<\/code>.&nbsp;<\/p>\n<p> \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 <code>EssentialAnswers<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 <code>augmen_tanswer<\/code>:&nbsp;<\/p>\n<pre><code class=\"python\"> x = input(\"Do you need the answer? (y\/n): \") if x.lower() == \"y\":     required = True else:     required = False       def the_answer(self, *args):                       return 42       class EssentialAnswers(type):          def __init__(cls, clsname, superclasses, attributedict):         if required:             cls.the_answer = the_answer                                  class Philosopher1(metaclass=EssentialAnswers):      pass   class Philosopher2(metaclass=EssentialAnswers):      pass   class Philosopher3(metaclass=EssentialAnswers):      pass           plato = Philosopher1() print(plato.the_answer())   kant = Philosopher2() # let's see what Kant has to say :-) print(kant.the_answer())<\/code><\/pre>\n<pre><code>Do you need the answer? (y\/n): y 42 42<\/code><\/pre>\n<p>  \u0412 \u0433\u043b\u0430\u0432\u0435 \u00abType and Class Relationship\u00bb \u043c\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Python \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442:<\/p>\n<pre><code class=\"python\">type(classname, superclasses, attributes_dict)<\/code><\/pre>\n<\/p>\n<p> \u041d\u043e \u043d\u0435 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441 \u0431\u044b\u043b \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u043c\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435. \u041d\u0430\u0448\u0438 \u043a\u043b\u0430\u0441\u0441\u044b <em>Philosopher1<\/em>, <em>Philosopher2<\/em> \u0438 <em>Philosopher3<\/em> \u0431\u044b\u043b\u0438 \u00ab\u043f\u0440\u0438\u0446\u0435\u043f\u043b\u0435\u043d\u044b\u00bb \u043a \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u0443 <em>EssentialAnswers<\/em>. \u0418 \u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 <em>EssentialAnswers<\/em> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0432\u043c\u0435\u0441\u0442\u043e <em>type<\/em>:<\/p>\n<pre><code class=\"python\">EssentialAnswer(classname, superclasses, attributes_dict)<\/code><\/pre>\n<\/p>\n<p> \u0415\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u043c, \u0442\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">EssentialAnswer('Philopsopher1',                  (),                  {'__module__': '__main__', '__qualname__': 'Philosopher1'})<\/code><\/pre>\n<p>    \u0414\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b <em>Philosopher<\/em> \u0431\u0443\u0434\u0443\u0442 \u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h3>\n<\/p>\n<p><strong>    <\/strong>\u0421\u0438\u043d\u0433\u043b\u0442\u043e\u043d&nbsp; &#8212; \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u0435\u043d \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442. \u041f\u043e\u043d\u044f\u0442\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0438\u043b\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c. \u0421\u0430\u043c \u0442\u0435\u0440\u043c\u0438\u043d \u043f\u0440\u0438\u0448\u0435\u043b \u043a \u043d\u0430\u043c \u0438\u0437 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438, \u0433\u0434\u0435 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d, \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0435\u0434\u0438\u043d\u0438\u0447\u043d\u044b\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0441 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c.<\/p>\n<pre><code class=\"python\">class Singleton(type):     _instances = {}     def __call__(cls, *args, **kwargs):         if cls not in cls._instances:             cls._instances[cls] = super(Singleton,                                      cls).__call__(*args, **kwargs)         return cls._instances[cls]           class SingletonClass(metaclass=Singleton):     pass   class RegularClass():     pass   x = SingletonClass() y = SingletonClass() print(x == y)   x = RegularClass() y = RegularClass() print(x == y)<\/code><\/pre>\n<pre><code>True False<\/code><\/pre>\n<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c Singleton-\u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f\u0441\u044c \u043e\u0442 <em>Singleton<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"python\">class Singleton(object):     _instance = None     def __new__(cls, *args, **kwargs):         if not cls._instance:             cls._instance = object.__new__(cls, *args, **kwargs)         return cls._instance       class SingletonClass(Singleton):     pass  class RegularClass():     pass   x = SingletonClass() y = SingletonClass() print(x == y)   x = RegularClass() y = RegularClass() print(x == y)<\/code><\/pre>\n<pre><code>True False<\/code><\/pre>\n<hr>\n<p><a href=\"https:\/\/otus.pw\/NAGBG\/\"><strong>\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0443\u0440\u0441\u0435.<\/strong><\/a><\/p>\n<hr>\n<h3>\u0427\u0438\u0442\u0430\u0442\u044c \u0435\u0449\u0451:<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/511840\/\">\u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FastAPI \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/510350\/\">\u0412 \u043a\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043a\u0438 \u0432 Python<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/509328\/\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 Python<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<p> \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\/otus\/blog\/527384\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/527384\/<\/a><br \/><\/br><\/br><\/hr>\n<\/hr>\n<\/div>\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-312891","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/312891","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=312891"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/312891\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=312891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=312891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=312891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}