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

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

      <small id='6oEWP'></small><noframes id='6oEWP'>

        如何編寫好的/正確的包 __init__.py 文件

        How do I write good/correct package __init__.py files(如何編寫好的/正確的包 __init__.py 文件)
          <i id='e2qeu'><tr id='e2qeu'><dt id='e2qeu'><q id='e2qeu'><span id='e2qeu'><b id='e2qeu'><form id='e2qeu'><ins id='e2qeu'></ins><ul id='e2qeu'></ul><sub id='e2qeu'></sub></form><legend id='e2qeu'></legend><bdo id='e2qeu'><pre id='e2qeu'><center id='e2qeu'></center></pre></bdo></b><th id='e2qeu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='e2qeu'><tfoot id='e2qeu'></tfoot><dl id='e2qeu'><fieldset id='e2qeu'></fieldset></dl></div>

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

            • <bdo id='e2qeu'></bdo><ul id='e2qeu'></ul>
                <tbody id='e2qeu'></tbody>
              <tfoot id='e2qeu'></tfoot>

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

                  本文介紹了如何編寫好的/正確的包 __init__.py 文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我的包有以下結構:

                  mobilescouter/
                      __init__.py #1
                      mapper/
                          __init__.py  #2
                          lxml/
                              __init__.py #3
                              vehiclemapper.py
                              vehiclefeaturemapper.py
                              vehiclefeaturesetmapper.py
                          ...
                          basemapper.py
                     vehicle/
                          __init__.py #4
                          vehicle.py
                          vehiclefeature.py
                          vehiclefeaturemapper.py
                     ...
                  

                  我不確定應該如何正確編寫 __init__.py 文件.
                  __init__.py #1 看起來像:

                  I'm not sure how the __init__.py files should be correctly written.
                  The __init__.py #1 looks like:

                  __all__ = ['mapper', 'vehicle']
                  import mapper
                  import vehicle
                  

                  但是例如 __init__.py #2 應該是什么樣子?我的是:

                  But how should for example __init__.py #2 look like? Mine is:

                  __all__ = ['basemapper', 'lxml']
                  from basemaper import *
                  import lxml
                  

                  什么時候應該使用 __all__?

                  推薦答案

                  __all__ 非常好 - 它有助于指導導入語句而不自動導入模塊http://docs.python.org/tutorial/modules.html#importing-from-a-package

                  __all__ is very good - it helps guide import statements without automatically importing modules http://docs.python.org/tutorial/modules.html#importing-from-a-package

                  使用 __all__import * 是多余的,只需要 __all__

                  using __all__ and import * is redundant, only __all__ is needed

                  我認為在 __init__.py 中使用 import * 來導入包的最有力的原因之一是能夠重構已經成長為多個的腳本在不破壞現有應用程序的情況下編寫腳本.但是如果你從一開始就設計一個包.我認為最好將 __init__.py 文件留空.

                  I think one of the most powerful reasons to use import * in an __init__.py to import packages is to be able to refactor a script that has grown into multiple scripts without breaking an existing application. But if you're designing a package from the start. I think it's best to leave __init__.py files empty.

                  例如:

                  foo.py - contains classes related to foo such as fooFactory, tallFoo, shortFoo
                  

                  然后應用程序增長,現在它是一個完整的文件夾

                  then the app grows and now it's a whole folder

                  foo/
                      __init__.py
                      foofactories.py
                      tallFoos.py
                      shortfoos.py
                      mediumfoos.py
                      santaslittlehelperfoo.py
                      superawsomefoo.py
                      anotherfoo.py
                  

                  那么初始化腳本可以說

                  __all__ = ['foofactories', 'tallFoos', 'shortfoos', 'medumfoos',
                             'santaslittlehelperfoo', 'superawsomefoo', 'anotherfoo']
                  # deprecated to keep older scripts who import this from breaking
                  from foo.foofactories import fooFactory
                  from foo.tallfoos import tallFoo
                  from foo.shortfoos import shortFoo
                  

                  以便為執行以下操作而編寫的腳本在更改期間不會中斷:

                  so that a script written to do the following does not break during the change:

                  from foo import fooFactory, tallFoo, shortFoo
                  

                  這篇關于如何編寫好的/正確的包 __init__.py 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 包)

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

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

                        <legend id='HuWU7'><style id='HuWU7'><dir id='HuWU7'><q id='HuWU7'></q></dir></style></legend>
                        <tfoot id='HuWU7'></tfoot>
                          <tbody id='HuWU7'></tbody>

                            主站蜘蛛池模板: 久草资源在线视频 | 亚洲高清电影 | 欧洲一区二区视频 | 日韩欧美在线免费观看 | 999re5这里只有精品 | 精品亚洲永久免费精品 | 91观看| 久久一区二区精品 | 日韩精品不卡 | av无遮挡 | 久久精品一区二区 | 亚洲一区亚洲二区 | 精品视频一区二区三区在线观看 | 中文字幕一区二区三区不卡 | 亚洲日本激情 | 欧美精品网 | 国产欧美日韩在线 | 国产日韩精品在线 | 国产乱码精品一区二区三区忘忧草 | 99成人 | 精品久久久久久久久久久久久久久久久 | 欧美天堂在线 | 亚洲一区二区三区在线视频 | 九九久久国产 | 欧美激情一区二区 | 婷婷91| 奇米四色在线观看 | 麻豆国产一区二区三区四区 | 黄色网址在线免费播放 | 日韩精品久久久 | 精品久久久一区二区 | 欧美日韩久久久久 | 视频一区二区在线观看 | 亚洲国产一区二区在线 | 亚洲av毛片成人精品 | 亚洲精品日韩在线观看 | 国产激情视频 | 免费污视频| 在线免费亚洲视频 | 久久久久国产一级毛片 | 国产精品一区二区三区在线 |