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

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

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

        NameError:未在類本身內部定義的類的名稱 - python

        NameError: name of the class not defined inside the class itself - python(NameError:未在類本身內部定義的類的名稱 - python)
        <legend id='HuDIl'><style id='HuDIl'><dir id='HuDIl'><q id='HuDIl'></q></dir></style></legend>

          <tbody id='HuDIl'></tbody>

          1. <small id='HuDIl'></small><noframes id='HuDIl'>

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

                • 本文介紹了NameError:未在類本身內部定義的類的名稱 - python的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有以下代碼:

                  import numpy as np
                  
                  class ClassProperty(property):
                      def __get__(self, cls, owner):
                          return self.fget.__get__(None, owner)()
                  
                  def coord(cls, c):
                      if cls.dimension <= 2:
                          return c
                      else:
                          return c + [0]*(cls.dimension-2)
                  
                  class Basis_NonI(object):
                  
                      @ClassProperty
                      @classmethod
                      def zerocoord(cls):
                          return coord(cls, [0,0])   
                          
                      def __init__(self, dimension):
                          pass
                  
                  class Basis_D(Basis_NonI):
                      dimension = 2
                      proj_matrix = np.array([Basis_D.zerocoord, Basis_D.zerocoord])
                      def __init__(self, dimension):
                          super(Basis_D, self).__init__(Basis_D.dimension)
                  

                  基本上我希望 dimensionproj_matrix 成為 Basis_D 的類屬性.

                  where basically I want dimension and proj_matrixto be class attributes of Basis_D.

                  當我運行它時,出現以下錯誤:

                  When I run it, the following error is given:

                  proj_matrix = np.array([Basis_D.zerocoord, Basis_D.zerocoord])

                  proj_matrix = np.array([Basis_D.zerocoord, Basis_D.zerocoord])

                  NameError:名稱Basis_D"未定義

                  NameError: name 'Basis_D' is not defined

                  --

                  我不明白的是,我可以在init中使用Basis_D.dimension,那么為什么在我使用它來定義時它不能識別名稱Basis_Dproj_matrix?

                  What I don't understand is that I can use Basis_D.dimension in the init, so why does it not recongise the name Basis_D when I use it to define proj_matrix?

                  推薦答案

                  class 是一個可執行語句.首次導入模塊時(對于給定進程),執行 class 語句頂層的所有代碼,以這種方式定義的所有名稱都收集到一個字典中,然后 >class 對象是用這個dict創建的,最后綁定到類名上.IOW,此時:

                  class is an executable statement. When the module is first imported (for a given process), all the code at the top-level of the class statement is executed, all names defined that way are collected into a dict, then the class object is created with this dict, and finally bound to the class name. IOW, at this point:

                  class Basis_D(Basis_NonI):
                     dimension = 2
                     # HERE
                     proj_matrix = np.array([Basis_D.zerocoord, Basis_D.zerocoord])
                  

                  該類尚未創建,也未綁定到名稱Basis_D.

                  the class has not yet been created nor bound to the name Basis_D.

                  現在調用 __init__ 時,該類已經創建并綁定到模塊級名稱 Basis_D,因此可以解析名稱.

                  Now by the time __init__ is called, the class has already been created and bound to the module-level name Basis_D, so the name can be resolved.

                  FWIW,你不應該在你的方法中直接引用 Basis_D,而是 type(self) (甚至是 self - 如果一個名字沒有解析為實例屬性,而是在類中查找).

                  FWIW, you shouldn't directly reference Basis_D in your methods, but type(self) (or even self - if a name is not resolved as an instance attribute, it's looked up on the class).

                  另外,你為什么堅持使用類屬性?您是否了解您的 project_matrix 數組將在 Basis_D 的所有實例之間共享?

                  Also, why do you insist on using class attributes ? Do you understand that your project_matrix array will be shared amongst all instances of Basis_D ?

                  這篇關于NameError:未在類本身內部定義的類的名稱 - python的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  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 包)
                • <legend id='D9c5d'><style id='D9c5d'><dir id='D9c5d'><q id='D9c5d'></q></dir></style></legend><tfoot id='D9c5d'></tfoot>

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

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

                        <bdo id='D9c5d'></bdo><ul id='D9c5d'></ul>

                            主站蜘蛛池模板: 国产亚洲一区精品 | 日本久久视频 | 久久精品小视频 | 精品一区二区三区不卡 | 国产在线精品一区二区三区 | 国产三级电影网站 | 国产成人精品午夜视频免费 | 日韩av最新网址 | 欧美日韩在线免费观看 | 午夜视频一区 | 国产91丝袜在线18 | 亚州激情| 最近免费日本视频在线 | 国产丝袜一区二区三区免费视频 | 91精品国产自产精品男人的天堂 | 欧美成人hd| 久久这里只有精品首页 | 日本大香伊一区二区三区 | 亚洲欧美日韩在线 | 亚洲区一 | 中文字幕在线三区 | 亚洲综合色站 | 国产精品视频免费播放 | 瑟瑟视频在线看 | 久久久国产一区二区三区四区小说 | 午夜婷婷激情 | 91视频网 | 国产日本精品视频 | 欧美日韩精品一区二区 | 亚洲精品视频在线看 | 人人鲁人人莫人人爱精品 | 国产精品99久久久精品免费观看 | 在线免费观看色 | 欧美日韩一 | 国产精品久久久久久亚洲调教 | 国产精品久久久久久吹潮 | 国产h视频 | 欧美xxxx黑人又粗又长 | 成人动慢 | 请别相信他免费喜剧电影在线观看 | 少妇一区在线观看 |