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

<small id='9D8De'></small><noframes id='9D8De'>

  • <tfoot id='9D8De'></tfoot>

      <legend id='9D8De'><style id='9D8De'><dir id='9D8De'><q id='9D8De'></q></dir></style></legend>

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

        如何在不重復導入頂級名稱的情況下構造python包

        How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)

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

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

            2. <legend id='O5uEw'><style id='O5uEw'><dir id='O5uEw'><q id='O5uEw'></q></dir></style></legend>
              <tfoot id='O5uEw'></tfoot>
                  <bdo id='O5uEw'></bdo><ul id='O5uEw'></ul>
                    <tbody id='O5uEw'></tbody>
                  本文介紹了如何在不重復導入頂級名稱的情況下構造python包的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我是 python 包管理的新手,肯定做錯了什么.我被鼓勵創建一個目錄結構如下:

                  I'm brand new at python package management, and surely have done something wrong. I was encouraged to create a directory structure as follows:

                  bagoftricks
                  ├── bagoftricks
                  │?? ├── bagoftricks
                  │?? │?? ├── __init__.py
                  │?? │?? └── bagoftricks.py
                  │?? └── __init__.py
                  ├── README.md
                  └── setup.py
                  

                  bagoftricks.py 包含兩個函數,levenshtein()geofind().

                  bagoftricks.py contains two functions, levenshtein() and geofind().

                  我想把它們稱為:

                  import bagoftricks
                  
                  x = bagoftricks.levenshtein(arg1,arg2) 
                  

                  相反,我發現我必須這樣做:

                  Instead, I find I have to do this:

                  import bagoftricks
                  
                  x = bagoftricks.bagoftricks.levenshtein(arg1,arg2) 
                  

                  有沒有更好的方法來組織我的包裹,而不用重復命名?

                  Is there a better way to organize my packages in the first place, without the naming redundancy?

                  更新

                  所以,我按照下面 Avichal Badaya 的說明,移除了一層嵌套.也就是說,我現在有……

                  So, I followed Avichal Badaya's instructions below, and removed one level of nesting. That is, I now have...

                  bagoftricks
                  ├── bagoftricks
                  │?? ├── __init__.py
                  │?? └── bagoftricks.py
                  ├── README.md
                  └── setup.py
                  

                  但是,要調用這個包,我還是有...

                  However, to call this package, I still have...

                  from bagoftricks.bagoftricks import geofind()
                  

                  import bagoftricks
                  

                  然后

                  >>> bagoftricks.bagoftricks.geofind()
                  

                  而不是想要的......

                  Rather than the desired....

                  from bagoftricks import geofind()
                  

                  import bagoftricks
                  
                  >>> bagoftricks.geofind()
                  

                  我無法移除額外的嵌套層.以此類推,當我嘗試移除一層嵌套時,我的模塊是扁平的,如下所示:

                  I cannot remove that extra layer of nesting. When I try, by analogy, to remove one more level of nesting, so that my module is flat, as:

                  bagoftricks
                  ├── __init__.py
                  ├── bagoftricks.py
                  ├── README.md
                  └── setup.py
                  

                  我根本無法構建包...

                  I cannot build the package at all...

                  $ python setup.py build
                  running build
                  running build_py
                  error: package directory 'bagoftricks' does not exist
                  

                  像標準包一樣使用自然導入,沒有多余的頂級名稱導入的秘訣是什么?

                  What's the secret for natural imports like standard packages use, without redundant top-level name imports?

                  推薦答案

                  第一級bagoftricks"就可以了.可以這么說,這只是您的項目"的名稱.在你有一個 setup.py 和其他文件告訴打包系統他們需要知道什么.

                  The first level "bagoftricks" is fine. That's just the name of your "project" so to speak. In the you have a setup.py, and other files that tell the packaging systems what they need to know.

                  然后您可以將代碼直接放在該模塊中,或者放在 src 目錄中.您甚至可以只使用這種結構:

                  You can then have the code directly in this module, or in a src directory. You can even go as far as just having this structure:

                  bagoftricks
                  ├── bagoftricks.py
                  ├── README.md
                  └── setup.py
                  

                  但我不建議這樣做,主要是因為您可能想稍后重新組織,如果您已經有一個合適的"包會更容易.此外,大多數人、工具和文檔都假設你有一個包,所以它更容易.

                  But I would not recommend that, mostly because you might want to reorganize things later, and it's easier if you already have a "proper" package. Also most people, tools and docs assume you have a package, so it's easier.

                  所以最小值是:

                  bagoftricks
                  ├── bagoftricks
                  │   └── __init__.py
                  ├── README.md
                  └── setup.py
                  

                  使用 __init__.py 包含您要導入的函數.然后你可以像這樣使用這些函數:

                  With __init__.py containing the functions you want to import. You then use these functions like this:

                  from bagoftricks import levenshtein, anotherfunction
                  

                  一旦 __init__.py 變得太大,你想把它分成幾個模塊,給你這樣的東西:

                  Once that __init__.py becomes too big, you want to split it up in several modules, giving you something like this:

                  bagoftricks
                  ├── bagoftricks
                  │   ├── __init__.py
                  │   ├── anothermodule.py
                  │   └── levenshtein.py
                  ├── README.md
                  └── setup.py
                  

                  您的 __init__.py 然后應該從各個模塊導入函數:

                  Your __init__.py should then import the functions from the various modules:

                  from bagoftricks.levenshtein import levenshtein
                  from bagoftricks.anothermodule import anotherfunction
                  

                  然后你仍然可以像以前一樣使用它們.

                  And then you can still use them like like you did before.

                  這篇關于如何在不重復導入頂級名稱的情況下構造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 以使用站點包的其他位置)
                  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 包)
                  R, Python: install packages on rpy2(R,Python:在 rpy2 上安裝包)
                • <i id='ZVJXp'><tr id='ZVJXp'><dt id='ZVJXp'><q id='ZVJXp'><span id='ZVJXp'><b id='ZVJXp'><form id='ZVJXp'><ins id='ZVJXp'></ins><ul id='ZVJXp'></ul><sub id='ZVJXp'></sub></form><legend id='ZVJXp'></legend><bdo id='ZVJXp'><pre id='ZVJXp'><center id='ZVJXp'></center></pre></bdo></b><th id='ZVJXp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ZVJXp'><tfoot id='ZVJXp'></tfoot><dl id='ZVJXp'><fieldset id='ZVJXp'></fieldset></dl></div>
                • <legend id='ZVJXp'><style id='ZVJXp'><dir id='ZVJXp'><q id='ZVJXp'></q></dir></style></legend>
                    <tbody id='ZVJXp'></tbody>

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

                        <bdo id='ZVJXp'></bdo><ul id='ZVJXp'></ul>
                          <tfoot id='ZVJXp'></tfoot>

                          • 主站蜘蛛池模板: 成年无码av片在线 | 粉嫩一区二区三区性色av | 精品综合网 | 中文字幕日韩一区 | 亚洲成人中文字幕 | 成人精品毛片 | 手机在线不卡av | 欧美激情在线播放 | 亚洲中午字幕 | 日韩久久精品 | 日本不卡免费新一二三区 | av片在线免费看 | 亚洲高清在线 | 先锋资源网 | 亚洲视频一区二区三区四区 | 毛片日韩| 999免费网站 | 久久久久久久久久久国产 | 巨大黑人极品videos精品 | 免费观看av | av一级久久 | 午夜爽爽男女免费观看hd | 久久精品久久久久久 | 亚洲一区二区电影网 | 人人人人干 | 欧美成人精品二区三区99精品 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 | 国产精品久久久久久52avav | 欧美11一13sex性hd| 国产不卡一区在线观看 | 中文字幕在线一区 | 中文区中文字幕免费看 | 天天插天天操 | 国产精品久久久久久久久久尿 | 91在线免费视频 | 91人人视频在线观看 | 黄色大片免费观看 | 亚洲视频一区二区三区 | 日韩免费视频一区二区 | 国产视频1 | 亚洲精品99|