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

  • <small id='tVP9T'></small><noframes id='tVP9T'>

    <i id='tVP9T'><tr id='tVP9T'><dt id='tVP9T'><q id='tVP9T'><span id='tVP9T'><b id='tVP9T'><form id='tVP9T'><ins id='tVP9T'></ins><ul id='tVP9T'></ul><sub id='tVP9T'></sub></form><legend id='tVP9T'></legend><bdo id='tVP9T'><pre id='tVP9T'><center id='tVP9T'></center></pre></bdo></b><th id='tVP9T'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tVP9T'><tfoot id='tVP9T'></tfoot><dl id='tVP9T'><fieldset id='tVP9T'></fieldset></dl></div>
    1. <tfoot id='tVP9T'></tfoot>
        <bdo id='tVP9T'></bdo><ul id='tVP9T'></ul>
      1. <legend id='tVP9T'><style id='tVP9T'><dir id='tVP9T'><q id='tVP9T'></q></dir></style></legend>
      2. Python 模塊的絕對與顯式相對導入

        Absolute vs. explicit relative import of Python module(Python 模塊的絕對與顯式相對導入)

        <legend id='A1LxZ'><style id='A1LxZ'><dir id='A1LxZ'><q id='A1LxZ'></q></dir></style></legend>

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

        1. <tfoot id='A1LxZ'></tfoot>
            • <i id='A1LxZ'><tr id='A1LxZ'><dt id='A1LxZ'><q id='A1LxZ'><span id='A1LxZ'><b id='A1LxZ'><form id='A1LxZ'><ins id='A1LxZ'></ins><ul id='A1LxZ'></ul><sub id='A1LxZ'></sub></form><legend id='A1LxZ'></legend><bdo id='A1LxZ'><pre id='A1LxZ'><center id='A1LxZ'></center></pre></bdo></b><th id='A1LxZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='A1LxZ'><tfoot id='A1LxZ'></tfoot><dl id='A1LxZ'><fieldset id='A1LxZ'></fieldset></dl></div>
                <tbody id='A1LxZ'></tbody>
                  <bdo id='A1LxZ'></bdo><ul id='A1LxZ'></ul>
                  本文介紹了Python 模塊的絕對與顯式相對導入的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想知道在 Python 應用程序中導入包的首選方式.我有一個這樣的包結構:

                  I'm wondering about the preferred way to import packages in a Python application. I have a package structure like this:

                  project.app1.models
                  project.app1.views
                  project.app2.models
                  

                  project.app1.views 導入 project.app1.modelsproject.app2.models.我想到了兩種方法.

                  project.app1.views imports project.app1.models and project.app2.models. There are two ways to do this that come to mind.

                  使用絕對導入:

                  import A.A
                  import A.B.B
                  

                  或使用顯式相對導入,如 帶有 PEP 328 的 Python 2.5:

                  or with explicit relative imports, as introduced in Python 2.5 with PEP 328:

                  # explicit relative
                  from .. import A
                  from . import B
                  

                  最pythonic的方法是什么?

                  What is the most pythonic way to do this?

                  推薦答案

                  絕對導入.從 PEP 8:

                  Absolute imports. From PEP 8:

                  包內導入的相對導入高度灰心.始終對所有導入使用絕對包路徑.即使現在 PEP 328 [7] 已在 Python 2.5 中完全實現,積極勸阻其明確的相對進口風格;絕對導入更便攜,通常更易讀.

                  Relative imports for intra-package imports are highly discouraged. Always use the absolute package path for all imports. Even now that PEP 328 [7] is fully implemented in Python 2.5, its style of explicit relative imports is actively discouraged; absolute imports are more portable and usually more readable.

                  顯式相對導入是一個不錯的語言功能(我猜),但它們不像絕對導入那樣顯式.更易讀的形式是:

                  Explicit relative imports are a nice language feature (I guess), but they're not nearly as explicit as absolute imports. The more readable form is:

                  import A.A
                  import A.B.B
                  

                  尤其是當您導入多個不同的命名空間時.如果您查看一些包含從包中導入的編寫良好的項目/教程,它們通常遵循這種風格.

                  especially if you import several different namespaces. If you look at some well written projects/tutorials that include imports from within packages, they usually follow this style.

                  您為了更明確而采取的一些額外擊鍵將為其他人(也許還有您)在將來嘗試找出您的命名空間時節省大量時間(特別是如果您遷移到 3.x,其中一些包名稱已更改).

                  The few extra keystrokes you take to be more explicit will save others (and perhaps you) plenty of time in the future when they're trying to figure out your namespace (especially if you migrate to 3.x, in which some of the package names have changed).

                  這篇關于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 包)

                  <small id='0ASDm'></small><noframes id='0ASDm'>

                      <bdo id='0ASDm'></bdo><ul id='0ASDm'></ul>
                        <tbody id='0ASDm'></tbody>

                          <legend id='0ASDm'><style id='0ASDm'><dir id='0ASDm'><q id='0ASDm'></q></dir></style></legend>

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

                          • 主站蜘蛛池模板: 天堂综合 | 亚洲综合久久久 | www.欧美| 亚洲国产精选 | 在线看亚洲 | 亚洲一区二区久久 | 亚洲精品一区二区三区在线 | 欧美a级成人淫片免费看 | 亚洲一区电影 | 日本精品久久久久 | 国产乡下妇女做爰 | 成人一区二区三区在线观看 | 国产视频福利 | 国产精品永久 | 亚洲综合色自拍一区 | 欧洲高清转码区一二区 | 国产黄色一级电影 | 午夜天堂精品久久久久 | 亚洲精品一区av在线播放 | 精品国产乱码久久久久久影片 | 日韩成年人视频在线 | 在线国产一区二区三区 | 99精品一区 | 国产三级精品视频 | 国产一级淫片免费视频 | 国产精品美女久久久久久免费 | 日韩在线视频一区 | 九九久久精品 | 欧美夜夜 | 男人天堂手机在线视频 | 久久精品视频网站 | 日韩视频在线一区二区 | 在线日韩欧美 | 粉嫩av久久一区二区三区 | 九九精品在线 | 亚洲一区在线免费观看 | 欧美日韩在线电影 | 欧美a区| 亚洲 欧美 精品 | 日韩欧美精品一区 | 91色站 |