{"id":313492,"date":"2020-11-20T15:01:39","date_gmt":"2020-11-20T15:01:39","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=313492"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=313492","title":{"rendered":"Functools \u2013 \u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p><strong>\u0414\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043a\u0443\u0440\u0441\u0430 <\/strong><a href=\"https:\/\/otus.pw\/svwL\/\"><strong>&#171;Python Developer. Basic&#187;<\/strong><\/a><strong> \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/strong><\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b0\/c23\/f6a\/3b0c23f6ab63573a50260f552fb8320d\" width=\"780\" height=\"439\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<hr>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/pymotw.com\/2\/functools\/#module-functools\">functools<\/a> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0438\u0445 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0446\u0435\u043b\u0435\u0439, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<h3>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h3>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c <em>functools<\/em> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <code>partial<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u00ab\u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f\u00bb \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041e\u0431\u044a\u0435\u043a\u0442, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0435 \u0436\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u0447\u0442\u043e \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.&nbsp;<\/p>\n<h4>partial<\/h4>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0434\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 partial<em> <\/em>\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>myfunc()<\/code>. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>show_details()<\/code> \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <code>func<\/code>, <code>args<\/code> \u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 partial<em> <\/em>\u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"python\">import functools  def myfunc(a, b=2):     \"\"\"Docstring for myfunc().\"\"\"     print '\\tcalled myfunc with:', (a, b)     return  def show_details(name, f, is_partial=False):     \"\"\"Show details of a callable object.\"\"\"     print '%s:' % name     print '\\tobject:', f     if not is_partial:         print '\\t__name__:', f.__name__     print '\\t__doc__', repr(f.__doc__)     if is_partial:         print '\\tfunc:', f.func         print '\\targs:', f.args         print '\\tkeywords:', f.keywords     return  show_details('myfunc', myfunc) myfunc('a', 3) print  p1 = functools.partial(myfunc, b=4) show_details('partial with named default', p1, True) p1('default a') p1('override b', b=5) print  p2 = functools.partial(myfunc, 'default a', b=99) show_details('partial with defaults', p2, True) p2() p2(b='override b') print  print 'Insufficient arguments:' p1()<\/code><\/pre>\n<\/p>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 <code>partial<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>a<\/code>, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.&nbsp;<\/p>\n<pre><code class=\"python\">$ python functools_partial.py  myfunc:         object: &lt;function myfunc at 0x100468c08&gt;         __name__: myfunc         __doc__ 'Docstring for myfunc().'         called myfunc with: ('a', 3)  partial with named default:         object: &lt;functools.partial object at 0x10046b050&gt;         __doc__ 'partial(func, *args, **keywords) - new function with partial  application\\n    of the given arguments and keywords.\\n'         func: &lt;function myfunc at 0x100468c08&gt;         args: ()         keywords: {'b': 4}         called myfunc with: ('default a', 4)         called myfunc with: ('override b', 5)  partial with defaults:         object: &lt;functools.partial object at 0x10046b0a8&gt;         __doc__ 'partial(func, *args, **keywords) - new function with partial  application\\n    of the given arguments and keywords.\\n'         func: &lt;function myfunc at 0x100468c08&gt;         args: ('default a',)         keywords: {'b': 99}         called myfunc with: ('default a', 99)         called myfunc with: ('default a', 'override b')  Insufficient arguments: Traceback (most recent call last):   File \"functools_partial.py\", line 49, in &lt;module&gt;     p1() TypeError: myfunc() takes at least 1 argument (1 given)<\/code><\/pre>\n<h4>update_wrapper<\/h4>\n<p>\u0423 partial \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 <code>_name_<\/code> \u0438\u043b\u0438 <code>_doc_<\/code> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0431\u0435\u0437 \u044d\u0442\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>update_wrapper()<\/code> \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 partial \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<pre><code class=\"python\">import functools  def myfunc(a, b=2):     \"\"\"Docstring for myfunc().\"\"\"     print '\\tcalled myfunc with:', (a, b)     return  def show_details(name, f):     \"\"\"Show details of a callable object.\"\"\"     print '%s:' % name     print '\\tobject:', f     print '\\t__name__:',      try:         print f.__name__     except AttributeError:         print '(no __name__)'     print '\\t__doc__', repr(f.__doc__)     print     return  show_details('myfunc', myfunc)  p1 = functools.partial(myfunc, b=4) show_details('raw wrapper', p1)  print 'Updating wrapper:' print '\\tassign:', functools.WRAPPER_ASSIGNMENTS print '\\tupdate:', functools.WRAPPER_UPDATES print  functools.update_wrapper(p1, myfunc) show_details('updated wrapper', p1)<\/code><\/pre>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 wrapper \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 <code>functools.WRAPPER_ASSIGNMENTS<\/code><em>, <\/em>\u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a<em> <\/em><code>functools.WRAPPER_UPDATES<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e.<\/p>\n<pre><code class=\"python\">$ python functools_update_wrapper.py  myfunc:         object: &lt;function myfunc at 0x100468c80&gt;         __name__: myfunc         __doc__ 'Docstring for myfunc().'  raw wrapper:         object: &lt;functools.partial object at 0x10046c0a8&gt;         __name__: (no __name__)         __doc__ 'partial(func, *args, **keywords) - new function with partial  application\\n    of the given arguments and keywords.\\n'  Updating wrapper:         assign: ('__module__', '__name__', '__doc__')         update: ('__dict__',)  updated wrapper:         object: &lt;functools.partial object at 0x10046c0a8&gt;         __name__: myfunc         __doc__ 'Docstring for myfunc().'<\/code><\/pre>\n<h3>\u0414\u0440\u0443\u0433\u0438\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b<\/h3>\n<p><em>Partial<\/em> \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043b\u044e\u0431\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438.<\/p>\n<pre><code class=\"python\">import functools  class MyClass(object):     \"\"\"Demonstration class for functools\"\"\"          def meth1(self, a, b=2):         \"\"\"Docstring for meth1().\"\"\"         print '\\tcalled meth1 with:', (self, a, b)         return          def meth2(self, c, d=5):         \"\"\"Docstring for meth2\"\"\"         print '\\tcalled meth2 with:', (self, c, d)         return     wrapped_meth2 = functools.partial(meth2, 'wrapped c')     functools.update_wrapper(wrapped_meth2, meth2)          def __call__(self, e, f=6):         \"\"\"Docstring for MyClass.__call__\"\"\"         print '\\tcalled object with:', (self, e, f)         return  def show_details(name, f):     \"\"\"Show details of a callable object.\"\"\"     print '%s:' % name     print '\\tobject:', f     print '\\t__name__:',      try:         print f.__name__     except AttributeError:         print '(no __name__)'     print '\\t__doc__', repr(f.__doc__)     return      o = MyClass()  show_details('meth1 straight', o.meth1) o.meth1('no default for a', b=3) print  p1 = functools.partial(o.meth1, b=4) functools.update_wrapper(p1, o.meth1) show_details('meth1 wrapper', p1) p1('a goes here') print  show_details('meth2', o.meth2) o.meth2('no default for c', d=6) print  show_details('wrapped meth2', o.wrapped_meth2) o.wrapped_meth2('no default for c', d=6) print  show_details('instance', o) o('no default for e') print  p2 = functools.partial(o, f=7) show_details('instance wrapper', p2) p2('e goes here')<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 partial \u0438\u0437 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/p>\n<pre><code class=\"python\">$ python functools_method.py  meth1 straight:         object: &lt;bound method MyClass.meth1 of &lt;__main__.MyClass object at 0x10046a3d0&gt;&gt;         __name__: meth1         __doc__ 'Docstring for meth1().'         called meth1 with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'no d efault for a', 3)  meth1 wrapper:         object: &lt;functools.partial object at 0x10046c158&gt;         __name__: meth1         __doc__ 'Docstring for meth1().'         called meth1 with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'a go es here', 4)  meth2:         object: &lt;bound method MyClass.meth2 of &lt;__main__.MyClass object at 0x10046a3d0&gt;&gt;         __name__: meth2         __doc__ 'Docstring for meth2'         called meth2 with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'no d efault for c', 6)  wrapped meth2:         object: &lt;functools.partial object at 0x10046c0a8&gt;         __name__: meth2         __doc__ 'Docstring for meth2'         called meth2 with: ('wrapped c', 'no default for c', 6)  instance:         object: &lt;__main__.MyClass object at 0x10046a3d0&gt;         __name__: (no __name__)         __doc__ 'Demonstration class for functools'         called object with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'no default for e', 6)  instance wrapper:         object: &lt;functools.partial object at 0x10046c1b0&gt;         __name__: (no __name__)         __doc__ 'partial(func, *args, **keywords) - new function with parti al application\\n    of the given arguments and keywords.\\n'         called object with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'e g oes here', 7)<\/code><\/pre>\n<h3>wraps<\/h3>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u043e\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u00ab\u0433\u043e\u043b\u043e\u0439\u00bb \u0444\u0443\u043d\u043a\u0446\u0438\u0438.&nbsp;<\/p>\n<pre><code class=\"python\">import functools  def show_details(name, f):     \"\"\"Show details of a callable object.\"\"\"     print '%s:' % name     print '\\tobject:', f     print '\\t__name__:',      try:         print f.__name__     except AttributeError:         print '(no __name__)'     print '\\t__doc__', repr(f.__doc__)     print     return  def simple_decorator(f):     @functools.wraps(f)     def decorated(a='decorated defaults', b=1):         print '\\tdecorated:', (a, b)         print '\\t',         f(a, b=b)         return     return decorated  def myfunc(a, b=2):     print '\\tmyfunc:', (a,b)     return  show_details('myfunc', myfunc) myfunc('unwrapped, default b') myfunc('unwrapped, passing b', 3) print  wrapped_myfunc = simple_decorator(myfunc) show_details('wrapped_myfunc', wrapped_myfunc) wrapped_myfunc() wrapped_myfunc('args to decorated', 4)<\/code><\/pre>\n<p><code>Functools<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>wraps()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 <code>update_wrapper()<\/code> \u043a \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0414\u043e Python 2 \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>_cmp_()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b <code>-1<\/code>, <code>0<\/code> \u0438\u043b\u0438 <code>1<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435, \u0440\u0430\u0432\u0435\u043d \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0447\u0435\u043c \u0442\u043e\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435. \u0412 Python 2.1 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0431\u043e\u0433\u0430\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, <code>_lt_()<\/code><em>, <\/em><code>_le_()<\/code><em>, <\/em><code>_eq_()<\/code><em>, <\/em><code>_ne_()<\/code><em>, <\/em><code>_gt_()<\/code><em> <\/em>\u0438<em> <\/em><code>_ge_()<\/code>, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0434\u043d\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0412 Python 3 \u0443\u0431\u0440\u0430\u043d <code>cmp()<\/code> \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u044d\u0442\u0438\u0445 \u043d\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <code>functools <\/code>\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0449\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0430 Python 2, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u043e\u0432\u044b\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0432 Python 3.<\/p>\n<h4>\u0411\u043e\u0433\u0430\u0442\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0411\u043e\u0433\u0430\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u043e\u0439\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0433\u0434\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c, \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430. \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>total_ordering()<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435.<\/p>\n<pre><code class=\"python\">import functools import inspect from pprint import pprint  @functools.total_ordering class MyObject(object):     def __init__(self, val):         self.val = val     def __eq__(self, other):         print '  testing __eq__(%s, %s)' % (self.val, other.val)         return self.val == other.val     def __gt__(self, other):         print '  testing __gt__(%s, %s)' % (self.val, other.val)         return self.val &gt; other.val  print 'Methods:\\n' pprint(inspect.getmembers(MyObject, inspect.ismethod))  a = MyObject(1) b = MyObject(2)  print '\\nComparisons:' for expr in [ 'a &lt; b', 'a &lt;= b', 'a == b', 'a &gt;= b', 'a &gt; b' ]:     print '\\n%-6s:' % expr     result = eval(expr)     print '  result of %s: %s' % (expr, result)<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>_eq_()<\/code> \u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0437 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430. \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"python\">$ python functools_total_ordering.py  Methods:  [('__eq__', &lt;unbound method MyObject.__eq__&gt;),  ('__ge__', &lt;unbound method MyObject.__ge__&gt;),  ('__gt__', &lt;unbound method MyObject.__gt__&gt;),  ('__init__', &lt;unbound method MyObject.__init__&gt;),  ('__le__', &lt;unbound method MyObject.__le__&gt;),  ('__lt__', &lt;unbound method MyObject.__lt__&gt;)]  Comparisons:  a &lt; b :   testing __gt__(1, 2)   testing __eq__(1, 2)   result of a &lt; b: True  a &lt;= b:   testing __gt__(1, 2)   result of a &lt;= b: True  a == b:   testing __eq__(1, 2)   result of a == b: False  a &gt;= b:   testing __gt__(1, 2)   testing __eq__(1, 2)   result of a &gt;= b: False  a &gt; b :   testing __gt__(1, 2)   result of a &gt; b: False<\/code><\/pre>\n<h4>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438<\/h4>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0442\u0430\u0440\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Python 3, \u0442\u043e \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>cmp<\/code> \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043a\u0430\u043a <code>sort()<\/code>. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0430 Python 2, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>cmp_to_key()<\/code> \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0443\u044e \u043a\u043b\u044e\u0447 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<pre><code class=\"python\">import functools  class MyObject(object):     def __init__(self, val):         self.val = val     def __str__(self):         return 'MyObject(%s)' % self.val  def compare_obj(a, b):     \"\"\"Old-style comparison function.     \"\"\"     print 'comparing %s and %s' % (a, b)     return cmp(a.val, b.val)  # Make a key function using cmp_to_key() get_key = functools.cmp_to_key(compare_obj)  def get_key_wrapper(o):     \"\"\"Wrapper function for get_key to allow for print statements.     \"\"\"     new_key = get_key(o)     print 'key_wrapper(%s) -&gt; %s' % (o, new_key)     return new_key  objs = [ MyObject(x) for x in xrange(5, 0, -1) ]  for o in sorted(objs, key=get_key_wrapper):     print o<\/code><\/pre>\n<p><em><u>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: <\/u>\u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, <\/em><code>cmp_to_key()<\/code><em> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/em><\/p>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e <code>sorted()<\/code> \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0432\u044b\u0437\u043e\u0432\u0430 <code>get_key_wrapper()<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0430. \u041a\u043b\u044e\u0447\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 <code>cmp_to_key()<\/code>, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432 <code>functools<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0441\u0442\u0438\u043b\u044f. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u0441\u0435 \u043a\u043b\u044e\u0447\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u2013 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0439.<\/p>\n<pre><code class=\"python\">$ python functools_cmp_to_key.py  key_wrapper(MyObject(5)) -&gt; &lt;functools.K object at 0x100466558&gt; key_wrapper(MyObject(4)) -&gt; &lt;functools.K object at 0x100466590&gt; key_wrapper(MyObject(3)) -&gt; &lt;functools.K object at 0x1004665c8&gt; key_wrapper(MyObject(2)) -&gt; &lt;functools.K object at 0x100466600&gt; key_wrapper(MyObject(1)) -&gt; &lt;functools.K object at 0x100466638&gt; comparing MyObject(4) and MyObject(5) comparing MyObject(3) and MyObject(4) comparing MyObject(2) and MyObject(3) comparing MyObject(1) and MyObject(2) MyObject(1) MyObject(2) MyObject(3) MyObject(4) MyObject(5)<\/code><\/pre>\n<hr>\n<blockquote>\n<p><a href=\"https:\/\/otus.pw\/svwL\/\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a> \u043e \u043a\u0443\u0440\u0441\u0435 &#171;Python Developer. Basic&#187;. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a \u043f\u043e \u0442\u0435\u043c\u0435 &#171;Pytest: \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u044b&#187; \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/otus.pw\/YlTL\/\">\u0437\u0434\u0435\u0441\u044c.<\/a><\/p>\n<\/blockquote>\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\/529072\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/529072\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p><strong>\u0414\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043a\u0443\u0440\u0441\u0430 <\/strong><a href=\"https:\/\/otus.pw\/svwL\/\"><strong>&#171;Python Developer. Basic&#187;<\/strong><\/a><strong> \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/strong><\/p>\n<\/blockquote>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<hr>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c <a href=\"https:\/\/pymotw.com\/2\/functools\/#module-functools\">functools<\/a> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0438\u0445 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0446\u0435\u043b\u0435\u0439, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<h3>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h3>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c <em>functools<\/em> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <code>partial<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u00ab\u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f\u00bb \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041e\u0431\u044a\u0435\u043a\u0442, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0435 \u0436\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u0447\u0442\u043e \u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.&nbsp;<\/p>\n<h4>partial<\/h4>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0434\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 partial<em> <\/em>\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>myfunc()<\/code>. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>show_details()<\/code> \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <code>func<\/code>, <code>args<\/code> \u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430 partial<em> <\/em>\u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"python\">import functools  def myfunc(a, b=2):     \"\"\"Docstring for myfunc().\"\"\"     print '\\tcalled myfunc with:', (a, b)     return  def show_details(name, f, is_partial=False):     \"\"\"Show details of a callable object.\"\"\"     print '%s:' % name     print '\\tobject:', f     if not is_partial:         print '\\t__name__:', f.__name__     print '\\t__doc__', repr(f.__doc__)     if is_partial:         print '\\tfunc:', f.func         print '\\targs:', f.args         print '\\tkeywords:', f.keywords     return  show_details('myfunc', myfunc) myfunc('a', 3) print  p1 = functools.partial(myfunc, b=4) show_details('partial with named default', p1, True) p1('default a') p1('override b', b=5) print  p2 = functools.partial(myfunc, 'default a', b=99) show_details('partial with defaults', p2, True) p2() p2(b='override b') print  print 'Insufficient arguments:' p1()<\/code><\/pre>\n<\/p>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 <code>partial<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>a<\/code>, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.&nbsp;<\/p>\n<pre><code class=\"python\">$ python functools_partial.py  myfunc:         object: &lt;function myfunc at 0x100468c08&gt;         __name__: myfunc         __doc__ 'Docstring for myfunc().'         called myfunc with: ('a', 3)  partial with named default:         object: &lt;functools.partial object at 0x10046b050&gt;         __doc__ 'partial(func, *args, **keywords) - new function with partial  application\\n    of the given arguments and keywords.\\n'         func: &lt;function myfunc at 0x100468c08&gt;         args: ()         keywords: {'b': 4}         called myfunc with: ('default a', 4)         called myfunc with: ('override b', 5)  partial with defaults:         object: &lt;functools.partial object at 0x10046b0a8&gt;         __doc__ 'partial(func, *args, **keywords) - new function with partial  application\\n    of the given arguments and keywords.\\n'         func: &lt;function myfunc at 0x100468c08&gt;         args: ('default a',)         keywords: {'b': 99}         called myfunc with: ('default a', 99)         called myfunc with: ('default a', 'override b')  Insufficient arguments: Traceback (most recent call last):   File \"functools_partial.py\", line 49, in &lt;module&gt;     p1() TypeError: myfunc() takes at least 1 argument (1 given)<\/code><\/pre>\n<h4>update_wrapper<\/h4>\n<p>\u0423 partial \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 <code>_name_<\/code> \u0438\u043b\u0438 <code>_doc_<\/code> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0431\u0435\u0437 \u044d\u0442\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>update_wrapper()<\/code> \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 partial \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<pre><code class=\"python\">import functools  def myfunc(a, b=2):     \"\"\"Docstring for myfunc().\"\"\"     print '\\tcalled myfunc with:', (a, b)     return  def show_details(name, f):     \"\"\"Show details of a callable object.\"\"\"     print '%s:' % name     print '\\tobject:', f     print '\\t__name__:',      try:         print f.__name__     except AttributeError:         print '(no __name__)'     print '\\t__doc__', repr(f.__doc__)     print     return  show_details('myfunc', myfunc)  p1 = functools.partial(myfunc, b=4) show_details('raw wrapper', p1)  print 'Updating wrapper:' print '\\tassign:', functools.WRAPPER_ASSIGNMENTS print '\\tupdate:', functools.WRAPPER_UPDATES print  functools.update_wrapper(p1, myfunc) show_details('updated wrapper', p1)<\/code><\/pre>\n<p>\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 wrapper \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 <code>functools.WRAPPER_ASSIGNMENTS<\/code><em>, <\/em>\u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a<em> <\/em><code>functools.WRAPPER_UPDATES<\/code> \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e.<\/p>\n<pre><code class=\"python\">$ python functools_update_wrapper.py  myfunc:         object: &lt;function myfunc at 0x100468c80&gt;         __name__: myfunc         __doc__ 'Docstring for myfunc().'  raw wrapper:         object: &lt;functools.partial object at 0x10046c0a8&gt;         __name__: (no __name__)         __doc__ 'partial(func, *args, **keywords) - new function with partial  application\\n    of the given arguments and keywords.\\n'  Updating wrapper:         assign: ('__module__', '__name__', '__doc__')         update: ('__dict__',)  updated wrapper:         object: &lt;functools.partial object at 0x10046c0a8&gt;         __name__: myfunc         __doc__ 'Docstring for myfunc().'<\/code><\/pre>\n<h3>\u0414\u0440\u0443\u0433\u0438\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b<\/h3>\n<p><em>Partial<\/em> \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043b\u044e\u0431\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438.<\/p>\n<pre><code class=\"python\">import functools  class MyClass(object):     \"\"\"Demonstration class for functools\"\"\"          def meth1(self, a, b=2):         \"\"\"Docstring for meth1().\"\"\"         print '\\tcalled meth1 with:', (self, a, b)         return          def meth2(self, c, d=5):         \"\"\"Docstring for meth2\"\"\"         print '\\tcalled meth2 with:', (self, c, d)         return     wrapped_meth2 = functools.partial(meth2, 'wrapped c')     functools.update_wrapper(wrapped_meth2, meth2)          def __call__(self, e, f=6):         \"\"\"Docstring for MyClass.__call__\"\"\"         print '\\tcalled object with:', (self, e, f)         return  def show_details(name, f):     \"\"\"Show details of a callable object.\"\"\"     print '%s:' % name     print '\\tobject:', f     print '\\t__name__:',      try:         print f.__name__     except AttributeError:         print '(no __name__)'     print '\\t__doc__', repr(f.__doc__)     return      o = MyClass()  show_details('meth1 straight', o.meth1) o.meth1('no default for a', b=3) print  p1 = functools.partial(o.meth1, b=4) functools.update_wrapper(p1, o.meth1) show_details('meth1 wrapper', p1) p1('a goes here') print  show_details('meth2', o.meth2) o.meth2('no default for c', d=6) print  show_details('wrapped meth2', o.wrapped_meth2) o.wrapped_meth2('no default for c', d=6) print  show_details('instance', o) o('no default for e') print  p2 = functools.partial(o, f=7) show_details('instance wrapper', p2) p2('e goes here')<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 partial \u0438\u0437 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/p>\n<pre><code class=\"python\">$ python functools_method.py  meth1 straight:         object: &lt;bound method MyClass.meth1 of &lt;__main__.MyClass object at 0x10046a3d0&gt;&gt;         __name__: meth1         __doc__ 'Docstring for meth1().'         called meth1 with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'no d efault for a', 3)  meth1 wrapper:         object: &lt;functools.partial object at 0x10046c158&gt;         __name__: meth1         __doc__ 'Docstring for meth1().'         called meth1 with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'a go es here', 4)  meth2:         object: &lt;bound method MyClass.meth2 of &lt;__main__.MyClass object at 0x10046a3d0&gt;&gt;         __name__: meth2         __doc__ 'Docstring for meth2'         called meth2 with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'no d efault for c', 6)  wrapped meth2:         object: &lt;functools.partial object at 0x10046c0a8&gt;         __name__: meth2         __doc__ 'Docstring for meth2'         called meth2 with: ('wrapped c', 'no default for c', 6)  instance:         object: &lt;__main__.MyClass object at 0x10046a3d0&gt;         __name__: (no __name__)         __doc__ 'Demonstration class for functools'         called object with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'no default for e', 6)  instance wrapper:         object: &lt;functools.partial object at 0x10046c1b0&gt;         __name__: (no __name__)         __doc__ 'partial(func, *args, **keywords) - new function with parti al application\\n    of the given arguments and keywords.\\n'         called object with: (&lt;__main__.MyClass object at 0x10046a3d0&gt;, 'e g oes here', 7)<\/code><\/pre>\n<h3>wraps<\/h3>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u043e\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u00ab\u0433\u043e\u043b\u043e\u0439\u00bb \u0444\u0443\u043d\u043a\u0446\u0438\u0438.&nbsp;<\/p>\n<pre><code class=\"python\">import functools  def show_details(name, f):     \"\"\"Show details of a callable object.\"\"\"     print '%s:' % name     print '\\tobject:', f     print '\\t__name__:',      try:         print f.__name__     except AttributeError:         print '(no __name__)'     print '\\t__doc__', repr(f.__doc__)     print     return  def simple_decorator(f):     @functools.wraps(f)     def decorated(a='decorated defaults', b=1):         print '\\tdecorated:', (a, b)         print '\\t',         f(a, b=b)         return     return decorated  def myfunc(a, b=2):     print '\\tmyfunc:', (a,b)     return  show_details('myfunc', myfunc) myfunc('unwrapped, default b') myfunc('unwrapped, passing b', 3) print  wrapped_myfunc = simple_decorator(myfunc) show_details('wrapped_myfunc', wrapped_myfunc) wrapped_myfunc() wrapped_myfunc('args to decorated', 4)<\/code><\/pre>\n<p><code>Functools<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 <code>wraps()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 <code>update_wrapper()<\/code> \u043a \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0414\u043e Python 2 \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>_cmp_()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b <code>-1<\/code>, <code>0<\/code> \u0438\u043b\u0438 <code>1<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435, \u0440\u0430\u0432\u0435\u043d \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0431\u044a\u0435\u043a\u0442, \u0447\u0435\u043c \u0442\u043e\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435. \u0412 Python 2.1 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0431\u043e\u0433\u0430\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, <code>_lt_()<\/code><em>, <\/em><code>_le_()<\/code><em>, <\/em><code>_eq_()<\/code><em>, <\/em><code>_ne_()<\/code><em>, <\/em><code>_gt_()<\/code><em> <\/em>\u0438<em> <\/em><code>_ge_()<\/code>, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0434\u043d\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0412 Python 3 \u0443\u0431\u0440\u0430\u043d <code>cmp()<\/code> \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u044d\u0442\u0438\u0445 \u043d\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <code>functools <\/code>\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0449\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0430 Python 2, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u043e\u0432\u044b\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0432 Python 3.<\/p>\n<h4>\u0411\u043e\u0433\u0430\u0442\u043e\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0411\u043e\u0433\u0430\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u043e\u0439\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0433\u0434\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c, \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430. \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>total_ordering()<\/code><\/p>\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-313492","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313492","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=313492"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313492\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}