久久久久久久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>

                            主站蜘蛛池模板: 成人在线中文字幕 | 亚洲精品一区二区三区中文字幕 | 国产精品一区二区三区四区 | 亚洲欧洲日韩 | 国产午夜精品久久久久 | 亚洲一区国产精品 | 国产欧美一区二区三区免费 | 亚洲精品久久久一区二区三区 | 狠狠色网 | 久久精品国产一区二区 | 激情一区二区三区 | 国产精品美女www爽爽爽 | 欧美一级片在线观看 | 日韩在线一区二区三区 | 91久久国产精品 | 人人草人人干 | 午夜免费网站 | 一级片成人 | 国产精品夜夜春夜夜爽久久电影 | 国产精品久久久久久久久免费丝袜 | 密室大逃脱第六季大神版在线观看 | 国产精品69久久久久水密桃 | 日韩av第一页 | 国产网站久久 | 九九视频在线观看视频6 | 欧美一二三| 91精品久久久久久久久 | 91视频大全 | 美女亚洲一区 | 亚洲综合第一页 | 国产视频福利在线观看 | 日韩在线一区二区 | 日韩一二区 | 中国美女撒尿txxxxx视频 | 亚洲精品一区二区三区蜜桃久 | 久久久久国产一区二区 | 欧美成年黄网站色视频 | www成人免费视频 | 91视视频在线观看入口直接观看 | 神马福利 | 亚洲精品二区 |