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

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

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

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

      1. 如何在 Python 中創建命名空間包?

        How do I create a namespace package in Python?(如何在 Python 中創建命名空間包?)
        <tfoot id='dHWkV'></tfoot>
        <i id='dHWkV'><tr id='dHWkV'><dt id='dHWkV'><q id='dHWkV'><span id='dHWkV'><b id='dHWkV'><form id='dHWkV'><ins id='dHWkV'></ins><ul id='dHWkV'></ul><sub id='dHWkV'></sub></form><legend id='dHWkV'></legend><bdo id='dHWkV'><pre id='dHWkV'><center id='dHWkV'></center></pre></bdo></b><th id='dHWkV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='dHWkV'><tfoot id='dHWkV'></tfoot><dl id='dHWkV'><fieldset id='dHWkV'></fieldset></dl></div>
      2. <legend id='dHWkV'><style id='dHWkV'><dir id='dHWkV'><q id='dHWkV'></q></dir></style></legend>
            <bdo id='dHWkV'></bdo><ul id='dHWkV'></ul>
          • <small id='dHWkV'></small><noframes id='dHWkV'>

              <tbody id='dHWkV'></tbody>

                  本文介紹了如何在 Python 中創建命名空間包?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在 Python 中,命名空間包允許您在多個項目之間傳播 Python 代碼.當您想要將相關庫作為單獨的下載發布時,這很有用.例如,使用 PYTHONPATH 中的目錄 Package-1Package-2,

                  In Python, a namespace package allows you to spread Python code among several projects. This is useful when you want to release related libraries as separate downloads. For example, with the directories Package-1 and Package-2 in PYTHONPATH,

                  Package-1/namespace/__init__.py
                  Package-1/namespace/module1/__init__.py
                  Package-2/namespace/__init__.py
                  Package-2/namespace/module2/__init__.py
                  

                  最終用戶可以import namespace.module1import namespace.module2.

                  定義一個命名空間包的最佳方式是什么,以便多個 Python 產品可以在該命名空間中定義模塊?

                  What's the best way to define a namespace package so more than one Python product can define modules in that namespace?

                  推薦答案

                  TL;DR:

                  在 Python 3.3 上,您無需執行任何操作,只需不要將任何 __init__.py 放入您的命名空間包目錄中,它就會正常工作.在 3.3 之前,選擇 pkgutil.extend_path() 解決方案而不是 pkg_resources.declare_namespace() 解決方案,因為它是面向未來的并且已經與隱式命名空間包兼容.

                  On Python 3.3 you don't have to do anything, just don't put any __init__.py in your namespace package directories and it will just work. On pre-3.3, choose the pkgutil.extend_path() solution over the pkg_resources.declare_namespace() one, because it's future-proof and already compatible with implicit namespace packages.

                  Python 3.3 引入了隱式命名空間包,請參閱 PEP 420.

                  Python 3.3 introduces implicit namespace packages, see PEP 420.

                  這意味著現在可以通過 import foo 創建三種類型的對象:

                  This means there are now three types of object that can be created by an import foo:

                  • foo.py 文件表示的模塊
                  • 一個常規包,由包含 __init__.py 文件的目錄 foo 表示
                  • 一個命名空間包,由一個或多個目錄 foo 表示,沒有任何 __init__.py 文件
                  • A module represented by a foo.py file
                  • A regular package, represented by a directory foo containing an __init__.py file
                  • A namespace package, represented by one or more directories foo without any __init__.py files

                  包也是模塊,但這里我說的模塊"是指非包模塊".

                  Packages are modules too, but here I mean "non-package module" when I say "module".

                  首先它會掃描 sys.path 以查找模塊或常規包.如果成功,它將停止搜索并創建和初始化模塊或包.如果它沒有找到模塊或常規包,但它至少找到一個目錄,它會創建并初始化一個命名空間包.

                  First it scans sys.path for a module or regular package. If it succeeds, it stops searching and creates and initalizes the module or package. If it found no module or regular package, but it found at least one directory, it creates and initializes a namespace package.

                  模塊和常規包將 __file__ 設置為創建它們的 .py 文件.常規和命名空間包的 __path__設置為創建它們的目錄.

                  Modules and regular packages have __file__ set to the .py file they were created from. Regular and namespace packages have __path__set to the directory or directories they were created from.

                  當你執行 import foo.bar 時,上面的搜索首先發生在 foo,然后如果找到一個包,則搜索 bar 使用 foo.__path__ 作為搜索路徑而不是 sys.path.如果找到 foo.bar,則創建并初始化 foofoo.bar.

                  When you do import foo.bar, the above search happens first for foo, then if a package was found, the search for bar is done with foo.__path__as the search path instead of sys.path. If foo.bar is found, foo and foo.bar are created and initialized.

                  那么常規包和命名空間包是如何混合的呢?通常它們不會,但舊的 pkgutil 顯式命名空間包方法已擴展為包含隱式命名空間包.

                  So how do regular packages and namespace packages mix? Normally they don't, but the old pkgutil explicit namespace package method has been extended to include implicit namespace packages.

                  如果您有一個現有的常規包,其中包含這樣的 __init__.py:

                  If you have an existing regular package that has an __init__.py like this:

                  from pkgutil import extend_path
                  __path__ = extend_path(__path__, __name__)
                  

                  ...遺留行為是將搜索到的路徑上的任何其他常規包添加到其__path__.但在 Python 3.3 中,它還添加了命名空間包.

                  ... the legacy behavior is to add any other regular packages on the searched path to its __path__. But in Python 3.3, it also adds namespace packages.

                  所以你可以有如下的目錄結構:

                  So you can have the following directory structure:

                  ├── path1
                  │?? └── package
                  │??     ├── __init__.py
                  │??     └── foo.py
                  ├── path2
                  │?? └── package
                  │??     └── bar.py
                  └── path3
                      └── package
                          ├── __init__.py
                          └── baz.py
                  

                  ...只要兩個 __init__.pyextend_path 行(和 path1、path2path3 在你的 sys.path) import package.foo, import package.barimport package.baz 一切正常.

                  ... and as long as the two __init__.py have the extend_path lines (and path1, path2 and path3 are in your sys.path) import package.foo, import package.bar and import package.baz will all work.

                  pkg_resources.declare_namespace(__name__) 尚未更新為包含隱式命名空間包.

                  pkg_resources.declare_namespace(__name__) has not been updated to include implicit namespace packages.

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

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

                    1. <legend id='7VktX'><style id='7VktX'><dir id='7VktX'><q id='7VktX'></q></dir></style></legend>
                        • <bdo id='7VktX'></bdo><ul id='7VktX'></ul>

                            主站蜘蛛池模板: 精精国产xxxx视频在线野外 | 午夜影视| 国产精品免费一区二区 | 欧美日韩电影一区 | 久久www免费人成看片高清 | 黄色大片免费网站 | 91九色porny首页最多播放 | 亚洲91精品 | 欧美韩一区二区 | 粉嫩一区二区三区国产精品 | 青青草社区 | 一区二区三区免费 | 日韩免费视频一区二区 | 国产精品伦理一区 | 国产精品久久亚洲 | 中文字幕免费视频 | 夜夜夜夜夜夜曰天天天 | 99re在线视频 | 91久久精品一区二区二区 | 国产成人99久久亚洲综合精品 | 人操人免费视频 | 日本超碰在线 | 99精品久久| 97色在线观看免费视频 | 成人久久久| 龙珠z在线观看 | 午夜电影一区二区 | 久久国产精品一区二区三区 | 亚洲视频欧美视频 | 精品久久久久久久久久久久久久久久久 | 日韩视频在线观看中文字幕 | 蜜臀网站 | 久久精品福利 | 亚洲精品乱码久久久久久黑人 | 久热m3u8 | 日韩中文字幕在线不卡 | 欧美日韩一区精品 | 成人九区 | 97精品超碰一区二区三区 | 国产精品一区二区三区在线 | 国产精品资源在线 |