久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    • <bdo id='uW4Ml'></bdo><ul id='uW4Ml'></ul>
      <legend id='uW4Ml'><style id='uW4Ml'><dir id='uW4Ml'><q id='uW4Ml'></q></dir></style></legend>
      1. <i id='uW4Ml'><tr id='uW4Ml'><dt id='uW4Ml'><q id='uW4Ml'><span id='uW4Ml'><b id='uW4Ml'><form id='uW4Ml'><ins id='uW4Ml'></ins><ul id='uW4Ml'></ul><sub id='uW4Ml'></sub></form><legend id='uW4Ml'></legend><bdo id='uW4Ml'><pre id='uW4Ml'><center id='uW4Ml'></center></pre></bdo></b><th id='uW4Ml'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uW4Ml'><tfoot id='uW4Ml'></tfoot><dl id='uW4Ml'><fieldset id='uW4Ml'></fieldset></dl></div>

        <tfoot id='uW4Ml'></tfoot>

        為什么從類和實例中獲取屬性的查找過程不同?

        Why are the lookup procedures for getting an attribute from a class and from an instance different?(為什么從類和實例中獲取屬性的查找過程不同?)

        <tfoot id='fue3N'></tfoot>

          <tbody id='fue3N'></tbody>
      2. <small id='fue3N'></small><noframes id='fue3N'>

        • <legend id='fue3N'><style id='fue3N'><dir id='fue3N'><q id='fue3N'></q></dir></style></legend>
          <i id='fue3N'><tr id='fue3N'><dt id='fue3N'><q id='fue3N'><span id='fue3N'><b id='fue3N'><form id='fue3N'><ins id='fue3N'></ins><ul id='fue3N'></ul><sub id='fue3N'></sub></form><legend id='fue3N'></legend><bdo id='fue3N'><pre id='fue3N'><center id='fue3N'></center></pre></bdo></b><th id='fue3N'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fue3N'><tfoot id='fue3N'></tfoot><dl id='fue3N'><fieldset id='fue3N'></fieldset></dl></div>
            <bdo id='fue3N'></bdo><ul id='fue3N'></ul>

                  本文介紹了為什么從類和實例中獲取屬性的查找過程不同?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  Python in a Nutshell 描述了獲取屬性時的查找過程.本書區分了兩種情況

                  Python in a Nutshell describes the lookup procedures when getting an attribute. The book distinguishes two cases

                  • 從類中獲取屬性時的查找過程,例如cls.name

                  從類中獲取屬性

                  當您使用語法 C.name 來引用屬性時在類對象 C 上,查找分兩步進行:

                  When you use the syntax C.name to refer to an attribute on a class object C, the lookup proceeds in two steps:

                  1. nameC.__dict__ 中的鍵時,C.name 獲取值 v 來自 C.__dict__['name'] .那么,當 v 是一個描述符(即 type(v) 提供一個名為__get__ ),C.name 的值是調用的結果type(v).__get__(v, None, C) .當 v 不是描述符時,C.name 的值為 v .

                  1. When name is a key in C.__dict__, C.name fetches the value v from C.__dict__['name'] . Then, when v is a descriptor (i.e., type(v) supplies a method named __get__ ), the value of C.name is the result of calling type(v).__get__(v, None, C) . When v is not a descriptor, the value of C.name is v .

                  name 不是 C.__dict__ 中的鍵時,C.name 將查找委托給 C 的基類,這意味著它在 C 上循環祖先類并嘗試對每個類進行名稱查找(在方法中解決順序,如頁面上的方法解決順序"中所述113).

                  When name is not a key in C.__dict__ , C.name delegates the lookup to C ’s base classes, meaning it loops on C ’s ancestor classes and tries the name lookup on each (in method resolution order, as covered in "Method resolution order" on page 113).

                1. 從實例獲取屬性時的查找過程,例如obj.name

                  由于在 Python 3 中,每個類對象實際上都是其元類的一個實例(例如 type 類),根據本書,為什么從類中獲取屬性的查找過程和從不同實例中獲取屬性的查找過程?

                  Since in Python 3, every class object is actually an instance of its metaclass (e.g. type class), according to the book, why are the lookup procedure for getting an attribute from a class and the lookup procedure for getting an attribute from an instance different?

                  推薦答案

                  它們并沒有非常不同,書中的描述涵蓋了它們不同的兩種方式:

                  They're not very different, and the description from the book covers the two ways in which they differ:

                  1. 在類實例上找到的描述符(在類上找不到之后)不會被調用(ax = somedescriptor() 其中 a 是一個類實例,不是一個類,后跟 ax 只會返回你剛剛創建的 somedescriptor() 的實例),而在元類實例上找到的描述符,即一個類(在沒有找到之后在元類上)以 None 作為它被調用的實例調用(Ax = somedescriptor() 其中 A 是元類實例,而不是一個元類,將在您剛剛創建的 somedescriptor() 上調用 .__get__(None, A) ).這允許像 @classmethod 這樣的東西通過將方法綁定到類本身來工作,無論它是在類的實例上還是在類本身上查找.
                  2. 類實例沒有父實例"的概念.(類實例本身的命名空間是一個扁平的dict,即使與該類實例關聯的屬性是由多個繼承級別的方法定義的),因此基于MRO的查找的想法是獨一無二的到元類實例.
                  1. Descriptors found on a class instance (after not being found on the class) don't get invoked (a.x = somedescriptor() where a is a class instance, not a class, followed by a.x will just return the instance of somedescriptor() you just made), while descriptors found on a metaclass instance i.e. a class (after not being found on the metaclass) get invoked with None as the instance it was called on (A.x = somedescriptor() where A is a metaclass instance, not a metaclass, will invoke .__get__(None, A) on the somedescriptor() you just made). This allows stuff like @classmethod to work by binding the method to the class itself whether it's looked up on an instance of the class or the class itself.
                  2. Class instances don't have a concept of "parent instances" (the namespace of the class instance itself is a flat dict, even if the attributes associated with that class instance were defined by methods from multiple levels of inheritance), so the idea of MRO-based lookup is unique to metaclass instances.

                  其他一切都差不多,只是本書在這里掩蓋了元類的概念,因為大多數類都是基本 type 的實例,沒有特殊行為.如果您有 type 以外的元類,則在查找類的屬性時會應用完整的實例查找規則(只是該類的類是元類).

                  Everything else is pretty much the same, it's just that the book is glossing over the concept of metaclasses here, since most classes are instances of the base type, which has no special behaviors. If you have a metaclass other than type, the full instance lookup rules apply when looking up attributes on a class (it's just the class of the class is the metaclass).

                  他們可能在早期試圖避免元類的復雜性,但在這個過程中,實例查找的規則似乎不適用于類;確實如此,只是類在基本查找過程中添加了一些額外的規則.

                  They were probably trying to avoid the complexity of metaclasses early on, but in the process made it seem like the rules for instance lookup didn't apply to classes; they do, it's just that classes add a couple extra rules to the basic lookup procedure.

                  這篇關于為什么從類和實例中獲取屬性的查找過程不同?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
                2. 相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

                  <tfoot id='KF3WG'></tfoot>

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

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

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

                              <tbody id='KF3WG'></tbody>
                            主站蜘蛛池模板: 亚州毛片 | 国产一级片免费视频 | 亚洲九色| 国产精品国产精品国产专区不卡 | 欧美午夜精品理论片a级按摩 | 亚洲女人天堂成人av在线 | 五月婷亚洲 | 黑人粗黑大躁护士 | 国产一级电影网 | 黄色成人免费看 | 中文字幕免费中文 | 国产精品欧美一区二区三区不卡 | 亚洲成人毛片 | 能看的av| 久久一二区 | av乱码| 国产99久久久国产精品 | 天天影视网天天综合色在线播放 | 欧美一级黄色片 | 日韩视频精品在线 | 美女爽到呻吟久久久久 | 性xxxxx| 精品日韩在线观看 | av片免费 | 久久成人国产精品 | 国产精品夜夜夜一区二区三区尤 | 成人性生交大片免费看r链接 | 91综合网 | 日韩精品在线免费观看 | 亚洲欧洲成人av每日更新 | 在线看av网址 | 日本三级网站在线 | 亚洲欧洲精品在线 | 国产欧美一区二区三区久久手机版 | 黄色国产在线视频 | 国产免费一区二区 | 欧美午夜剧场 | 久久九精品 | 国产网站在线播放 | 久久久久久久久久久爱 | 欧美日产国产成人免费图片 |