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

    • <bdo id='hVlCk'></bdo><ul id='hVlCk'></ul>

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

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

    2. <tfoot id='hVlCk'></tfoot>
      1. <legend id='hVlCk'><style id='hVlCk'><dir id='hVlCk'><q id='hVlCk'></q></dir></style></legend>

        將代碼添加到 __init__.py

        Adding code to __init__.py(將代碼添加到 __init__.py)

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

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

            <tfoot id='PYmZ7'></tfoot>
              • <bdo id='PYmZ7'></bdo><ul id='PYmZ7'></ul>
                  本文介紹了將代碼添加到 __init__.py的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在查看 django 中的模型系統是如何工作的,我發現了一些我不明白的地方.

                  I'm taking a look at how the model system in django works and I noticed something that I don't understand.

                  我知道你創建了一個空的 __init__.py 文件來指定當前目錄是一個包.并且您可以在 __init__.py 中設置一些變量,以便 import * 正常工作.

                  I know that you create an empty __init__.py file to specify that the current directory is a package. And that you can set some variable in __init__.py so that import * works properly.

                  但是django在__init__.py中添加了一堆from ... import ...語句并定義了一堆類.為什么?這不是讓事情看起來很亂嗎?__init__.py 中是否有需要此代碼的原因?

                  But django adds a bunch of from ... import ... statements and defines a bunch of classes in __init__.py. Why? Doesn't this just make things look messy? Is there a reason that requires this code in __init__.py?

                  推薦答案

                  當你導入包含它的包(目錄)時,__init__.py 中的所有導入都可用.

                  All imports in __init__.py are made available when you import the package (directory) that contains it.

                  例子:

                  ./dir/__init__.py:

                  import something
                  

                  ./test.py:

                  import dir
                  # can now use dir.something
                  

                  忘了提一下,__init__.py 中的代碼在您第一次從該目錄導入任何模塊時運行.所以它通常是放置任何包級初始化代碼的好地方.

                  forgot to mention, the code in __init__.py runs the first time you import any module from that directory. So it's normally a good place to put any package-level initialisation code.

                  dgrant 在我的示例中指出了可能的混淆.在 __init__.py import something 可以導入任何模塊,不需要從包中導入.例如,我們可以將其替換為 import datetime,然后在我們的頂級 test.py 中,這兩個片段都可以工作:

                  dgrant pointed out to a possible confusion in my example. In __init__.py import something can import any module, not necessary from the package. For example, we can replace it with import datetime, then in our top level test.py both of these snippets will work:

                  import dir
                  print dir.datetime.datetime.now()
                  

                  import dir.some_module_in_dir
                  print dir.datetime.datetime.now()
                  

                  底線是:在 __init__.py 中分配的所有名稱,無論是導入的模塊、函數還是類,在您導入包或包中的模塊時自動在包命名空間中可用.

                  The bottom line is: all names assigned in __init__.py, be it imported modules, functions or classes, are automatically available in the package namespace whenever you import the package or a module in the package.

                  這篇關于將代碼添加到 __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 包)

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

                        <legend id='7VYeY'><style id='7VYeY'><dir id='7VYeY'><q id='7VYeY'></q></dir></style></legend>

                            <tfoot id='7VYeY'></tfoot>
                          1. <small id='7VYeY'></small><noframes id='7VYeY'>

                              <tbody id='7VYeY'></tbody>

                            主站蜘蛛池模板: 亚洲欧美另类在线观看 | 亚洲精品91天天久久人人 | 亚洲视频在线观看 | 99热在线免费观看 | 99九九久久 | 国产成人在线免费视频 | 成人国产精品久久久网站 | 一区二区三区四区国产 | 国产黄色一区二区 | 久草视频在线播放 | 天堂av网站 | 日韩精品一区二区三区四区 | 欧美精品一级片 | 看国产毛片 | 日韩免费精品视频 | 国产精品久久视频 | 91国产视频在线观看 | 99热国产在线 | 91丨porny丨成人蝌蚪 | 五月婷婷丁香综合 | 欧美一级黄色片 | 免费看黄色的视频 | 一级真人毛片 | 日韩伦理视频 | 亚洲美女网站 | 午夜影院在线观看 | 久久久久国产精品夜夜夜夜夜 | 欧美日韩免费视频 | 久久久久国产视频 | 日韩精品一级 | 黄色国产| 免费看一级黄色片 | 婷婷久久五月天 | 国产免费黄色片 | 中文字幕一级片 | 女人av在线 | 国产精品福利视频 | 天堂va蜜桃一区二区三区 | 玖草在线 | 国产tv| 欧美视频久久 |