{"id":324178,"date":"2021-06-02T09:00:16","date_gmt":"2021-06-02T09:00:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324178"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324178","title":{"rendered":"\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b Python: \u0445\u0432\u0430\u0442\u0438\u0442 \u044d\u0442\u043e \u0442\u0435\u0440\u043f\u0435\u0442\u044c"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/18a\/685\/a60\/18a685a609168a80d0e2e4f16a4a3fb8.jpg\" alt=\"\u041a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u0430\u0434\u0430\u043d\u0438\u044f\u043c.\" title=\"\u041a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u0430\u0434\u0430\u043d\u0438\u044f\u043c.\" width=\"1600\" height=\"1050\"><figcaption>\u041a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u0430\u0434\u0430\u043d\u0438\u044f\u043c.<\/figcaption><\/figure>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0435, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u043c \u043c\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 Python \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u0445 \u0431\u043e\u043b\u0435\u0435 \u00ab\u041f\u0438\u0442\u043e\u043d\u0438\u0447\u043d\u044b\u043c\u0438\u00bb.<\/p>\n<p><strong>\u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432.<\/strong> \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c: \u0447\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0432 \u041f\u0430\u0439\u0442\u043e\u043d.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e, \u0442\u043e \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0440\u0435\u0442\u044c\u044e. \u0412 \u044d\u0442\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043d\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u0430\u0432\u0434\u044b, \u043d\u043e \u043c\u044b \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f!<\/p>\n<h2>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<pre><code class=\"python\">def decorator_function(wrapped_func):     def wrapper():         print('\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043e\u0431\u0451\u0440\u0442\u043a\u0443')         print('\u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f: ', wrapped_func)         print('\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e...')         wrapped_func()         print('\u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043e\u0431\u0451\u0440\u0442\u043a\u0438')     return wrapper<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440. \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0417\u0430\u0442\u0435\u043c \u0441 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043e\u0431\u0451\u0440\u0442\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0438\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0443\u0436\u0435 \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">@decorator_function def hello_world():         print('Hello world!') hello_world()<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>hello_world<\/code>, \u0438 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u0442 \u0435\u0451 \u0441\u0432\u043e\u0435\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>wrapper<\/code>.<\/p>\n<p>\u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:  &lt;function hello_world at 0x0201B2F8&gt; \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e... Hello world! \u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043e\u0431\u0451\u0440\u0442\u043a\u0438<\/code><\/pre>\n<p><strong><u>\u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c!<\/u><\/strong><\/p>\n<p><em>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437: \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u0440\u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <\/em><code>wrapper<\/code><em>.<\/em><\/p>\n<p>\u041c\u044b \u044d\u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0435\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0432 \u043d\u0430\u0448 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"python\">def decorator_function(wrapped_func):     print('\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440')     def wrapper():         ...     print('\u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430')     return wrapper<\/code><\/pre>\n<pre><code class=\"python\">@decorator_function def hello_world():         print('Hello world!')<\/code><\/pre>\n<pre><code>\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430<\/code><\/pre>\n<pre><code class=\"python\">hello_world()<\/code><\/pre>\n<pre><code>\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:  &lt;function hello_world at 0x0201B2F8&gt; \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e... Hello world! \u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043e\u0431\u0451\u0440\u0442\u043a\u0438<\/code><\/pre>\n<h2>\u0410 \u0432\u043e\u0442 \u0438 \u0441\u0442\u0440\u0430\u0434\u0430\u043d\u0438\u044f: \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430<\/h2>\n<p>\u0423 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c, \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u0445 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>wrapper<\/code>:<\/p>\n<pre><code class=\"python\">def decorator_function(wrapped_func):     def wrapper(*args):         ...         wrapped_func(args)         ...     return wrapper    @decorator_function def hello_world(text):         print(text)      hello_world('Hello world!')<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0451, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"python\">def fictive(decorator_text):     def decorator_function(wrapped_func):                  def wrapper(*args):             print(decorator_text, end='')             wrapped_func(*args)         return wrapper          return decorator_function  @fictive(decorator_text='Hello, ') def hello_world(text):         print(text) hello_world('world!')<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>decorator_text<\/code>  \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u0438 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u211611 \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>fictive<\/code>, \u0441\u0442\u0440\u043e\u043a\u0430 \u21161. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>\u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>Hello, world!<\/code><\/pre>\n<p>\u041f\u043e\u0439\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432 \u043e\u0434\u043d\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 &#8212; \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432? \u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<pre><code class=\"python\">def fictive(_func=None, *, decorator_text=''):     def decorator_function(wrapped_func):         def wrapper(*args):             print(decorator_text, end='')             wrapped_func(*args)         return wrapper     if _func is None:         return decorator_function     else:         return decorator_function(_func)        @fictive def hello_world(text):         print(text) hello_world('Hello, world!')  @fictive(decorator_text='Hi, ') def say(text):         print(text) say('world!')<\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>Hello, world! Hi, world!<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0412\u0430\u043c \u043a\u043e\u0434? \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043c\u0430\u043d\u0442\u0440\u0443 \u041f\u0438\u0442\u043e\u043d\u0438\u0441\u0442\u043e\u0432 \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<blockquote>\n<p><strong>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b &#8212; \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431<\/strong> \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c&#8230;<\/p>\n<\/blockquote>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e, \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0434\u0451\u0442 DecoratorHelper! \u041d\u043e, \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c, \u0435\u0449\u0451 \u043f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430\u0445.<\/p>\n<h2>\u041c\u0438\u0444\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/h2>\n<ol>\n<li>\n<p><strong>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0443\u0434\u043e\u0431\u043d\u044b.<\/strong> \u0414\u0443\u043c\u0430\u044e, \u0441 \u044d\u0442\u0438\u043c \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/strong> \u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438 \u043b\u044e\u0431\u044b\u0435 callable \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u042d\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0434\u0430\u043d\u0434\u0435\u0440 \u043c\u0435\u0442\u043e\u0434 (\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434) <code>__call__<\/code>. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u044b \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (\u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u0442\u0430\u0432\u0438\u0442\u0435 \u0441\u043a\u043e\u0431\u043e\u0447\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0438\u043c\u0435\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430: <code>object()<\/code>). \u0412\u043c\u0435\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441.    <\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b &#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/strong> \u0418 \u043e\u043f\u044f\u0442\u044c: \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0439 callable \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/strong> \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <u>\u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e<\/u><em>. <\/em>\u0421\u0442\u043e\u0438\u0442 \u043b\u0438\u0448\u044c \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435 callable \u043e\u0431\u044a\u0435\u043a\u0442, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u0412\u043c\u0435\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b. <\/p>\n<\/li>\n<li><\/li>\n<\/ol>\n<hr>\n<h2>DecoratorHelper: \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c<\/h2>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<pre><code>pip install DecoratorHelper<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u0430\u043a \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"python\">from DecoratorHelper import DecoratorHelper  @DecoratorHelper def hello_world(text):         print(text) hello_world('Hello, world!')<\/code><\/pre>\n<p><strong>\u0427\u0442\u043e \u044d\u0442\u043e \u0434\u0430\u0451\u0442?<\/strong><\/p>\n<ol>\n<li>\n<p>\u0412\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u043d\u0430\u0434 \u0442\u0435\u043c, \u0431\u0443\u0434\u0443\u0442 \u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0443 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430. DecoratorHelper \u0434\u0443\u043c\u0430\u0435\u0442 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432\u043c\u0435\u0441\u0442\u043e \u0412\u0430\u0441.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u041f\u0438\u0442\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c, \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>self.function &#8212; \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>self.decorator_args&nbsp;&#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430. \u041a\u043e\u0440\u0442\u0435\u0436 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e &#8212; \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>self.function_args&nbsp;&#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041a\u043e\u0440\u0442\u0435\u0436 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e &#8212; \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>self.pre_function &#8212; \u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a).<\/p>\n<\/li>\n<li>\n<p>self.post_function &#8212; \u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c?<\/strong><\/p>\n<p>\u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u0440\u0430\u043d\u0435\u0435 \u043a\u043e\u0434 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c\/\u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:<\/p>\n<pre><code class=\"python\">from DecoratorHelper import DecoratorHelper  def fictive(object):     object.pre_function = lambda : print(*object.decorator_args[:-1], end='')     return object      @fictive @DecoratorHelper('Hello, ') def hello_world(text):         print(text) hello_world('world!')<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c, \u0442\u0435\u043b\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u043e\u0441\u044c \u0432 8 \u0440\u0430\u0437. Profit!<\/p>\n<p><strong>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435!<\/strong> \u041f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c callable \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0438\u043d\u0430\u0447\u0435 \u0432\u0441\u0451 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \ud83d\ude42 \u0414\u0443\u043c\u0430\u044e, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u0447, \u044d\u0442\u043e \u043d\u0435 \u0441\u043c\u0435\u0440\u0442\u0435\u043b\u044c\u043d\u043e&#8230;<\/p>\n<p><strong>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/strong><\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0443\u0438\u043b\u0434\u0435\u0440.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0418 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435: <code>singleton = True.<\/code><\/p>\n<\/li>\n<\/ul>\n<p>P. S. \u0415\u0441\u043b\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u043a \u0442\u0435\u043c\u0435, \u043d\u0430\u043f\u0438\u0448\u0443 \u0432\u0442\u043e\u0440\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a DecoratorHelper \u0443\u0441\u0442\u0440\u043e\u0435\u043d. \u041d\u043e \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u044d\u0442\u043e \u0443\u0440\u043e\u0432\u0435\u043d\u044c Junior+.<\/p>\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\/post\/560572\/\"> https:\/\/habr.com\/ru\/post\/560572\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption>\u041a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u0430\u0434\u0430\u043d\u0438\u044f\u043c.<\/figcaption><\/figure>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0435, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u043c \u043c\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 Python \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u0445 \u0431\u043e\u043b\u0435\u0435 \u00ab\u041f\u0438\u0442\u043e\u043d\u0438\u0447\u043d\u044b\u043c\u0438\u00bb.<\/p>\n<p><strong>\u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432.<\/strong> \u0415\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c: \u0447\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0432 \u041f\u0430\u0439\u0442\u043e\u043d.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e, \u0442\u043e \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0440\u0435\u0442\u044c\u044e. \u0412 \u044d\u0442\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043d\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u0430\u0432\u0434\u044b, \u043d\u043e \u043c\u044b \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f!<\/p>\n<h2>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<pre><code class=\"python\">def decorator_function(wrapped_func):     def wrapper():         print('\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043e\u0431\u0451\u0440\u0442\u043a\u0443')         print('\u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f: ', wrapped_func)         print('\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e...')         wrapped_func()         print('\u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043e\u0431\u0451\u0440\u0442\u043a\u0438')     return wrapper<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440. \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u0417\u0430\u0442\u0435\u043c \u0441 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043e\u0431\u0451\u0440\u0442\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0438\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0443\u0436\u0435 \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">@decorator_function def hello_world():         print('Hello world!') hello_world()<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>hello_world<\/code>, \u0438 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u0442 \u0435\u0451 \u0441\u0432\u043e\u0435\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>wrapper<\/code>.<\/p>\n<p>\u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:  &lt;function hello_world at 0x0201B2F8&gt; \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e... Hello world! \u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043e\u0431\u0451\u0440\u0442\u043a\u0438<\/code><\/pre>\n<p><strong><u>\u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c!<\/u><\/strong><\/p>\n<p><em>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437: \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u0440\u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <\/em><code>wrapper<\/code><em>.<\/em><\/p>\n<p>\u041c\u044b \u044d\u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0435\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0432 \u043d\u0430\u0448 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"python\">def decorator_function(wrapped_func):     print('\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440')     def wrapper():         ...     print('\u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430')     return wrapper<\/code><\/pre>\n<pre><code class=\"python\">@decorator_function def hello_world():         print('Hello world!')<\/code><\/pre>\n<pre><code>\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430<\/code><\/pre>\n<pre><code class=\"python\">hello_world()<\/code><\/pre>\n<pre><code>\u0412\u0445\u043e\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:  &lt;function hello_world at 0x0201B2F8&gt; \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u0431\u0451\u0440\u043d\u0443\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e... Hello world! \u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043e\u0431\u0451\u0440\u0442\u043a\u0438<\/code><\/pre>\n<h2>\u0410 \u0432\u043e\u0442 \u0438 \u0441\u0442\u0440\u0430\u0434\u0430\u043d\u0438\u044f: \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430<\/h2>\n<p>\u0423 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u0435\u043c, \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u0445 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>wrapper<\/code>:<\/p>\n<pre><code class=\"python\">def decorator_function(wrapped_func):     def wrapper(*args):         ...         wrapped_func(args)         ...     return wrapper    @decorator_function def hello_world(text):         print(text)      hello_world('Hello world!')<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0451, \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"python\">def fictive(decorator_text):     def decorator_function(wrapped_func):                  def wrapper(*args):             print(decorator_text, end='')             wrapped_func(*args)         return wrapper          return decorator_function  @fictive(decorator_text='Hello, ') def hello_world(text):         print(text) hello_world('world!')<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>decorator_text<\/code>  \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u0438 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u211611 \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>fictive<\/code>, \u0441\u0442\u0440\u043e\u043a\u0430 \u21161. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>\u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>Hello, world!<\/code><\/pre>\n<p>\u041f\u043e\u0439\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432 \u043e\u0434\u043d\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 &#8212; \u0431\u0435\u0437 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432? \u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<pre><code class=\"python\">def fictive(_func=None, *, decorator_text=''):     def decorator_function(wrapped_func):         def wrapper(*args):             print(decorator_text, end='')             wrapped_func(*args)         return wrapper     if _func is None:         return decorator_function     else:         return decorator_function(_func)        @fictive def hello_world(text):         print(text) hello_world('Hello, world!')  @fictive(decorator_text='Hi, ') def say(text):         print(text) say('world!')<\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>Hello, world! Hi, world!<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0412\u0430\u043c \u043a\u043e\u0434? \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043c\u0430\u043d\u0442\u0440\u0443 \u041f\u0438\u0442\u043e\u043d\u0438\u0441\u0442\u043e\u0432 \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<blockquote>\n<p><strong>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b &#8212; \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431<\/strong> \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c&#8230;<\/p>\n<\/blockquote>\n<p>\u041d\u0438\u0447\u0435\u0433\u043e, \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0434\u0451\u0442 DecoratorHelper! \u041d\u043e, \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c, \u0435\u0449\u0451 \u043f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430\u0445.<\/p>\n<h2>\u041c\u0438\u0444\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/h2>\n<ol>\n<li>\n<p><strong>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u0443\u0434\u043e\u0431\u043d\u044b.<\/strong> \u0414\u0443\u043c\u0430\u044e, \u0441 \u044d\u0442\u0438\u043c \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/strong> \u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438 \u043b\u044e\u0431\u044b\u0435 callable \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u042d\u0442\u043e \u0442\u0430\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0434\u0430\u043d\u0434\u0435\u0440 \u043c\u0435\u0442\u043e\u0434 (\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434) <code>__call__<\/code>. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u044b \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (\u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u0442\u0430\u0432\u0438\u0442\u0435 \u0441\u043a\u043e\u0431\u043e\u0447\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0438\u043c\u0435\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430: <code>object()<\/code>). \u0412\u043c\u0435\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441.    <\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b &#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/strong> \u0418 \u043e\u043f\u044f\u0442\u044c: \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0439 callable \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/strong> \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <u>\u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e<\/u><em>. <\/em>\u0421\u0442\u043e\u0438\u0442 \u043b\u0438\u0448\u044c \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435 callable \u043e\u0431\u044a\u0435\u043a\u0442, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u0412\u043c\u0435\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b. <\/p>\n<\/li>\n<li><\/li>\n<\/ol>\n<hr>\n<h2>DecoratorHelper: \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c<\/h2>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<pre><code>pip install DecoratorHelper<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u0430\u043a \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"python\">from DecoratorHelper import DecoratorHelper  @DecoratorHelper def hello_world(text):         print(text) hello_world('Hello, world!')<\/code><\/pre>\n<p><strong>\u0427\u0442\u043e \u044d\u0442\u043e \u0434\u0430\u0451\u0442?<\/strong><\/p>\n<ol>\n<li>\n<p>\u0412\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u043d\u0430\u0434 \u0442\u0435\u043c, \u0431\u0443\u0434\u0443\u0442 \u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0443 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430. DecoratorHelper \u0434\u0443\u043c\u0430\u0435\u0442 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432\u043c\u0435\u0441\u0442\u043e \u0412\u0430\u0441.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u041f\u0438\u0442\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c, \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>self.function &#8212; \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>self.decorator_args&nbsp;&#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430. \u041a\u043e\u0440\u0442\u0435\u0436 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e &#8212; \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>self.function_args&nbsp;&#8212; \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041a\u043e\u0440\u0442\u0435\u0436 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e &#8212; \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0441 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>self.pre_function &#8212; \u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a).<\/p>\n<\/li>\n<li>\n<p>self.post_function &#8212; \u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c?<\/strong><\/p>\n<p>\u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u0440\u0430\u043d\u0435\u0435 \u043a\u043e\u0434 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c\/\u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:<\/p>\n<pre><code class=\"python\">from DecoratorHelper import DecoratorHelper  def fictive(object):     object.pre_function = lambda : print(*object.decorator_args[:-1], end='')     return object      @fictive @DecoratorHelper('Hello, ') def hello_world(text):         print(text) hello_world('world!')<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c, \u0442\u0435\u043b\u043e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u043e\u0441\u044c \u0432 8 \u0440\u0430\u0437. Profit!<\/p>\n<p><strong>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435!<\/strong> \u041f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c callable \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0438\u043d\u0430\u0447\u0435 \u0432\u0441\u0451 \u0441\u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \ud83d\ude42 \u0414\u0443\u043c\u0430\u044e, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u0447, \u044d\u0442\u043e \u043d\u0435 \u0441\u043c\u0435\u0440\u0442\u0435\u043b\u044c\u043d\u043e&#8230;<\/p>\n<p><strong>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/strong><\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0443\u0438\u043b\u0434\u0435\u0440.<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0418 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435: <code>singleton = True.<\/code><\/p>\n<\/li>\n<\/ul>\n<p>P. S. \u0415\u0441\u043b\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u043a \u0442\u0435\u043c\u0435, \u043d\u0430\u043f\u0438\u0448\u0443 \u0432\u0442\u043e\u0440\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a DecoratorHelper \u0443\u0441\u0442\u0440\u043e\u0435\u043d. \u041d\u043e \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u044d\u0442\u043e \u0443\u0440\u043e\u0432\u0435\u043d\u044c Junior+.<\/p>\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\/post\/560572\/\"> https:\/\/habr.com\/ru\/post\/560572\/<\/a><br \/><\/br><\/br><\/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-324178","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324178","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=324178"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324178\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}