<bdo id='YfnKp'></bdo><ul id='YfnKp'></ul>
      <i id='YfnKp'><tr id='YfnKp'><dt id='YfnKp'><q id='YfnKp'><span id='YfnKp'><b id='YfnKp'><form id='YfnKp'><ins id='YfnKp'></ins><ul id='YfnKp'></ul><sub id='YfnKp'></sub></form><legend id='YfnKp'></legend><bdo id='YfnKp'><pre id='YfnKp'><center id='YfnKp'></center></pre></bdo></b><th id='YfnKp'></th></span></q></dt></tr></i><div id='YfnKp'><tfoot id='YfnKp'></tfoot><dl id='YfnKp'><fieldset id='YfnKp'></fieldset></dl></div>
    1. <small id='YfnKp'></small><noframes id='YfnKp'>

    2. <tfoot id='YfnKp'></tfoot>
      <legend id='YfnKp'><style id='YfnKp'><dir id='YfnKp'><q id='YfnKp'></q></dir></style></legend>

        什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?

        时间:2023-09-03
        • <legend id='iAzQy'><style id='iAzQy'><dir id='iAzQy'><q id='iAzQy'></q></dir></style></legend>
          <i id='iAzQy'><tr id='iAzQy'><dt id='iAzQy'><q id='iAzQy'><span id='iAzQy'><b id='iAzQy'><form id='iAzQy'><ins id='iAzQy'></ins><ul id='iAzQy'></ul><sub id='iAzQy'></sub></form><legend id='iAzQy'></legend><bdo id='iAzQy'><pre id='iAzQy'><center id='iAzQy'></center></pre></bdo></b><th id='iAzQy'></th></span></q></dt></tr></i><div id='iAzQy'><tfoot id='iAzQy'></tfoot><dl id='iAzQy'><fieldset id='iAzQy'></fieldset></dl></div>
              <tbody id='iAzQy'></tbody>

              <small id='iAzQy'></small><noframes id='iAzQy'>

              • <bdo id='iAzQy'></bdo><ul id='iAzQy'></ul>
                <tfoot id='iAzQy'></tfoot>
                • 本文介绍了什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  import inspect
                  
                  class Foo(object):
                      pass
                  
                  if __name__ == '__main__':
                      print type(Foo.__init__)
                      print inspect.getsourcelines(Foo.__init__)
                  

                  输出:

                  <type 'wrapper_descriptor'>
                  Traceback (most recent call last):
                    *snip*
                    File "/usr/lib/python2.7/inspect.py", line 420, in getfile
                      'function, traceback, frame, or code object'.format(object))
                  TypeError: <slot wrapper '__init__' of 'object' objects> is not a module, class, method, function, traceback, frame, or code object
                  

                  Google 几乎没有提供关于 wrapper_descriptor 究竟是什么以及为什么空类有一个不是方法而是 wrapper_descriptor 的 __init__ 方法的有用信息.

                  Googling gives very little useful information about what, exactly, a wrapper_descriptor is, and why an empty class has an __init__ method that is not a method, but rather a wrapper_descriptor.

                  这里到底发生了什么?没有 __init__ 方法的所有类都具有这些 wrapper_descriptor 事物之一吗?为什么类字典中有一个 __init__?

                  What exactly is going on here? Do all classes without __init__ methods have one of these wrapper_descriptor things? Why is there an __init__ in the class dict at all?

                  推荐答案

                  你遇到的是一个实现细节.这对于用 C 实现的类来说是非常典型的,就像 object 一样.它不是 Python 方法,而是 C 方法,包装器是该接口的一部分.

                  What you've run into is an implementation detail. This is pretty typical for classes implemented in C, as object is. It's not a Python method, it is a C method, and the wrapper is part of this interface.

                  为什么类字典中有一个 __init__?

                  Why is there an __init__ in the class dict at all?

                  它不在类字典中,它在 object 字典中.object 有一个 __init__ ,因此当您尝试使用 super() 调用类的基类的 __init__ 方法时,它不会失败.

                  It's not in the class dict, it's in the object dict. object has an __init__ so that when you try to call your class's base classes' __init__ methods using super(), it doesn't fail.

                  这篇关于什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用相同的布尔值初始化列表 下一篇:dict() 和 {} 有什么区别?

                  相关文章

                  • <bdo id='dnR9Q'></bdo><ul id='dnR9Q'></ul>

                    <legend id='dnR9Q'><style id='dnR9Q'><dir id='dnR9Q'><q id='dnR9Q'></q></dir></style></legend>
                  1. <tfoot id='dnR9Q'></tfoot>

                      <i id='dnR9Q'><tr id='dnR9Q'><dt id='dnR9Q'><q id='dnR9Q'><span id='dnR9Q'><b id='dnR9Q'><form id='dnR9Q'><ins id='dnR9Q'></ins><ul id='dnR9Q'></ul><sub id='dnR9Q'></sub></form><legend id='dnR9Q'></legend><bdo id='dnR9Q'><pre id='dnR9Q'><center id='dnR9Q'></center></pre></bdo></b><th id='dnR9Q'></th></span></q></dt></tr></i><div id='dnR9Q'><tfoot id='dnR9Q'></tfoot><dl id='dnR9Q'><fieldset id='dnR9Q'></fieldset></dl></div>

                      <small id='dnR9Q'></small><noframes id='dnR9Q'>