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

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

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

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

      2. 是否可以使用兩個具有相同名稱的 Python 包?

        Is it possible to use two Python packages with the same name?(是否可以使用兩個具有相同名稱的 Python 包?)

        • <legend id='GomGf'><style id='GomGf'><dir id='GomGf'><q id='GomGf'></q></dir></style></legend>

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

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

                  <tfoot id='GomGf'></tfoot>
                    <tbody id='GomGf'></tbody>
                1. <i id='GomGf'><tr id='GomGf'><dt id='GomGf'><q id='GomGf'><span id='GomGf'><b id='GomGf'><form id='GomGf'><ins id='GomGf'></ins><ul id='GomGf'></ul><sub id='GomGf'></sub></form><legend id='GomGf'></legend><bdo id='GomGf'><pre id='GomGf'><center id='GomGf'></center></pre></bdo></b><th id='GomGf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='GomGf'><tfoot id='GomGf'></tfoot><dl id='GomGf'><fieldset id='GomGf'></fieldset></dl></div>
                  本文介紹了是否可以使用兩個具有相同名稱的 Python 包?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個關(guān)于進口的問題.這個問題可能看起來有點做作,但它的目的是探索對包中的所有導入使用絕對導入的限制.PEP8 強烈反對相對導入(和 Google Python 風格指南 說永遠不要使用它們).

                  假設(shè)您有兩個同名的大型軟件包,并且都使用符合 PEP8 的絕對導入:

                  <上一頁>/pkg1mod1.py(包含絕對導入:'import pkg1.mod2')模組2.py.../pkg1mod1.py(包含絕對導入:'import pkg1.mod3')模組3.py...

                  另外說你正在處理一個 Python 項目,你想在其中使用這兩個包.例如,如果您想在一個項目中使用同一包的兩個版本,則可能會出現(xiàn)這種情況.

                  有沒有辦法將這兩個包合并到您的項目層次結(jié)構(gòu)中,以便您可以在整個項目中自由使用這兩個包中的模塊?

                  對于解決方案,可以使用導入別名和臨時修改 sys.path 之類的操作.但是不可以隨便改動一個包目錄的內(nèi)容.

                  解決方案

                  簡短的回答是否定的,Python 不接受兩個同名的包.(有些東西稱為命名空間包",它允許在多個目錄中實現(xiàn)單個包,但它們需要設(shè)置所涉及的包以相互協(xié)作.

                  PEP 8 不鼓勵顯式相對導入的方式是其更值得懷疑的建議之一,正是因為它使得重命名包以避免命名沖突變得更加困難.如果這兩個包使用相對導入,您可以重命名其中一個或?qū)⑵淝短自诹硪粋€包中并完成.

                  import aliases 在這里對您沒有幫助,因為重要的是以 sys.modules 結(jié)尾的名稱,并且它使用導入的模塊名稱,而不是最終被綁定在導入模塊中.

                  如果你想獲得真正的異國情調(diào),你可以編寫自己的導入器(參見 PEP 302 和 3.x importlib 文檔).如果你決定走那么遠,你幾乎可以做任何你想做的事情.

                  I have a question about imports. The question might seem a bit contrived, but its purpose is to explore the limitations of using absolute imports for all imports in a package. PEP8 highly discourages relative imports (edit: and the Google Python Style Guide says never to use them).

                  Say you are given two large-ish packages that both have the same name and that both use absolute imports in accordance with PEP8:

                      /pkg1
                          mod1.py (contains an absolute import: 'import pkg1.mod2')
                          mod2.py
                          ...
                  
                      /pkg1
                          mod1.py (contains an absolute import: 'import pkg1.mod3')
                          mod3.py
                          ...
                  

                  Also say you are working on a Python project in which you'd like to use both packages. This could come up, say, if you want to use two versions of the same package in a project.

                  Is there a way to incorporate both packages into your project hierarchy so that you can freely use modules from both packages throughout your project?

                  For the solution it's acceptable to do things like use import aliases and modify sys.path temporarily. But it's not okay to change the contents of either package directory.

                  解決方案

                  The short answer is no, Python doesn't accept two packages with the same name. (There are things called "namespace packages" that let a single package be implemented over multiple directories but they require the packages involved to be set up to cooperate with each other).

                  The way PEP 8 discourages explicit relative imports is one of its more questionable pieces of advice, precisely because it makes it harder to rename a package to avoid naming conflicts. If the two packages used relative imports, you could just rename one of them or nest it inside another package and be done with it.

                  import aliases won't help you here, because it is the name that ends up in sys.modules that matters, and that uses the name of the module as imported, rather than the name that ends up being bound in the importing module.

                  If you wanted to get really exotic, you could write your own importer (see PEP 302 and the 3.x importlib documentation). If you decide to go that far, you can do pretty much anything you want.

                  這篇關(guān)于是否可以使用兩個具有相同名稱的 Python 包?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  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(如何在不重復導入頂級名稱的情況下構(gòu)造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(分發(fā)帶有已編譯動態(tài)共享庫的 Python 包)

                      <tbody id='9d3kZ'></tbody>
                      • <bdo id='9d3kZ'></bdo><ul id='9d3kZ'></ul>

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

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

                      • <legend id='9d3kZ'><style id='9d3kZ'><dir id='9d3kZ'><q id='9d3kZ'></q></dir></style></legend>

                          1. <tfoot id='9d3kZ'></tfoot>
                            主站蜘蛛池模板: 正在播放一区二区 | 久久精品97 | 午夜激情免费 | 亚洲毛片在线 | 日本高清视频在线播放 | 国产一区二区电影网 | 亚洲黄色成人网 | 秋霞电影一区二区 | 国产日韩欧美在线播放 | 中文字幕精品一区 | 999久久久久久久久6666 | 亚洲综合精品 | 日韩一区二区在线视频 | 久久久久久久久淑女av国产精品 | 色婷婷av久久久久久久 | av看片网| 精品国产乱码久久久久久牛牛 | 国产精品色哟哟网站 | 久久久爽爽爽美女图片 | 国产传媒在线播放 | 波多野结衣精品 | 国产精品久久久久久久免费大片 | 91国产在线播放 | 久久欧美精品 | 99re国产精品| 一区二区不卡高清 | 日韩三片 | h视频免费在线观看 | 国产麻豆一区二区三区 | 亚洲国产中文字幕 | 国产精品视频免费看 | 精品亚洲一区二区三区四区五区 | 国产日韩精品久久 | 一级做a毛片| 久久国产精品偷 | 亚洲成人a v | 成人精品国产 | 精品综合久久久 | 国产精品久久久久久久久久久免费看 | 久久久综合精品 | 日本免费在线观看视频 |