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

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

        <tfoot id='eJunj'></tfoot>

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

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

      1. 具有相同名稱的 Python 模塊(即在包中重用標準模

        Python modules with identical names (i.e., reusing standard module names in packages)(具有相同名稱的 Python 模塊(即在包中重用標準模塊名稱))
        1. <i id='XfMzU'><tr id='XfMzU'><dt id='XfMzU'><q id='XfMzU'><span id='XfMzU'><b id='XfMzU'><form id='XfMzU'><ins id='XfMzU'></ins><ul id='XfMzU'></ul><sub id='XfMzU'></sub></form><legend id='XfMzU'></legend><bdo id='XfMzU'><pre id='XfMzU'><center id='XfMzU'></center></pre></bdo></b><th id='XfMzU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='XfMzU'><tfoot id='XfMzU'></tfoot><dl id='XfMzU'><fieldset id='XfMzU'></fieldset></dl></div>

          <legend id='XfMzU'><style id='XfMzU'><dir id='XfMzU'><q id='XfMzU'></q></dir></style></legend>
        2. <small id='XfMzU'></small><noframes id='XfMzU'>

                <tbody id='XfMzU'></tbody>

                  <bdo id='XfMzU'></bdo><ul id='XfMzU'></ul>
                  <tfoot id='XfMzU'></tfoot>
                  本文介紹了具有相同名稱的 Python 模塊(即在包中重用標準模塊名稱)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  假設我有一個包含模塊的包:

                  Suppose I have a package that contains modules:

                  SWS/
                    __init.py__
                    foo.py
                    bar.py
                    time.py
                  

                  并且模塊需要引用彼此包含的函數.我的 time.py 模塊似乎遇到了問題,因為有一個同名的標準模塊.

                  and the modules need to refer to functions contained in one another. It seems like I run into problems with my time.py module since there is a standard module that goes by the same name.

                  例如,如果我的 foo.py 模塊需要我的 SWS.time 和標準 python time 模塊,我遇到麻煩,因為解釋器會在包內部查找我的 time.py 模塊,然后再遇到標準 time 模塊.

                  For instance, in the case that my foo.py module requires both my SWS.time and the standard python time modules, I run into trouble since the interpreter will look inside the package and find my time.py modules before it comes across the standard time module.

                  有沒有辦法解決這個問題?這是禁止的情況嗎?不應該重復使用模塊名稱嗎?

                  Is there any way around this? Is this a no-no situation and should modules names not be reused?

                  任何關于包裝理念的解決方案和意見都會在這里有用.

                  Any solutions and opinions on package philosophy would be useful here.

                  推薦答案

                  重用標準函數/類/模塊/包的名稱絕不是一個好主意.盡量避免它.但是,對于您的情況,有一些干凈的解決方法.

                  Reusing names of standard functions/classes/modules/packages is never a good idea. Try to avoid it as much as possible. However there are clean workarounds to your situation.

                  您看到的行為,導入您的 SWS.time 而不是 stdlib time,是由于古代 python 中 import 的語義版本(2.x).要修復它,請添加:

                  The behaviour you see, importing your SWS.time instead of the stdlib time, is due to the semantics of import in ancient python versions (2.x). To fix it add:

                  from __future__ import absolute_import
                  

                  在文件的最頂部.這會將 import 的語義更改為 python3.x 的語義,這更加明智.在這種情況下,聲明:

                  at the very top of the file. This will change the semantics of import to that of python3.x, which are much more sensible. In that case the statement:

                  import time
                  

                  只會引用頂級模塊.因此,在包內執行該導入時,解釋器不會考慮您的 SWS.time 模塊,但它只會使用標準庫之一.

                  Will only refer to a top-level module. So the interpreter will not consider your SWS.time module when executing that import inside the package, but it will only use the standard library one.

                  如果你的包內部中的一個模塊需要導入SWS.time,你可以選擇:

                  If a module inside your package needs to import SWS.time you have the choice of:

                  • 使用顯式相對導入:

                  from . import time
                  

                • 使用絕對導入:

                • Using an absolute import:

                  import SWS.time as time
                  

                • 因此,您的 foo.py 將類似于:

                  So, your foo.py would be something like:

                  from __future__ import absolute_import
                  
                  import time
                  
                  from . import time as SWS_time
                  

                  這篇關于具有相同名稱的 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 包)
                    <tbody id='petUd'></tbody>
                  <legend id='petUd'><style id='petUd'><dir id='petUd'><q id='petUd'></q></dir></style></legend>
                • <tfoot id='petUd'></tfoot>
                  • <bdo id='petUd'></bdo><ul id='petUd'></ul>

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

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

                            主站蜘蛛池模板: 欧美日韩一区二区三区四区 | 在线精品一区 | 一区二区三区国产视频 | 欧美午夜片 | 中文字幕在线播放视频 | av最新在线| 特级西西444www大胆免费看 | 成人三级视频在线观看 | 国产91在线播放 | 国产精品www | 99热综合| 国产日韩一区 | 日本不卡一区 | 黄色成人在线 | 两性免费视频 | 国产小精品 | 精品久久精品 | 亚洲 欧美 综合 | 欧美激情视频网站 | 超碰精品在线 | 黄色成人毛片 | 91精品成人 | 欧美三级韩国三级日本三斤在线观看 | www.99riav| 中文字字幕 | www.国产精品 | 久久福利网| 久久久久久九九九九 | 色综合一区 | www.男人的天堂 | 日韩国产精品视频 | 黄色免费网站在线观看 | 国产tv| 中文久久久| 日韩欧美国产一区二区三区 | 人人艹人人 | 日本免费一级片 | 亚洲精品无 | 亚洲人在线 | 日韩精品少妇 | 日韩av手机在线观看 |