久久久久久久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的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在查看 django 中的模型系統(tǒng)是如何工作的,我發(fā)現(xiàn)了一些我不明白的地方.

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

                  我知道你創(chuàng)建了一個空的 __init__.py 文件來指定當(dāng)前目錄是一個包.并且您可以在 __init__.py 中設(shè)置一些變量,以便 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?

                  推薦答案

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

                  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 中的代碼在您第一次從該目錄導(dǎo)入任何模塊時運行.所以它通常是放置任何包級初始化代碼的好地方.

                  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 可以導(dǎo)入任何模塊,不需要從包中導(dǎo)入.例如,我們可以將其替換為 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 中分配的所有名稱,無論是導(dǎo)入的模塊、函數(shù)還是類,在您導(dǎo)入包或包中的模塊時自動在包命名空間中可用.

                  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.

                  這篇關(guān)于將代碼添加到 __init__.py的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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(如何在不重復(fù)導(dǎo)入頂級名稱的情況下構(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 包)

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

                            主站蜘蛛池模板: 日本午夜精品 | 久久久久国产一级毛片 | www.夜夜骑 | 夜久久| 欧美成人精品一区二区男人看 | 羞视频在线观看 | 国产精品久久 | 国产视频日韩 | 日韩国产一区二区 | 日韩视频在线免费观看 | 日韩第一区 | 中文字幕在线观看第一页 | 国产一区 | 日韩久草| 日本精品视频一区二区三区四区 | 宅女噜噜66国产精品观看免费 | 四虎成人免费电影 | 国产精品视频 | 97av视频| 国产高清视频 | 日韩免费一区二区 | 亚洲精品播放 | 亚洲精品视频一区二区三区 | 91视视频在线观看入口直接观看 | 久久高清| 中文字幕高清视频 | 欧美日韩免费在线 | 欧美中文字幕一区二区 | 国产97在线看| 欧美日韩免费视频 | 欧美日韩一区二区在线 | 久草视频2 | 成人久久18免费网站麻豆 | aaaaaa大片免费看最大的 | 欧美电影在线观看网站 | 成人国产精品久久久 | 夜夜夜夜夜夜曰天天天 | 高清成人免费视频 | 亚洲一区二区三区免费观看 | 国产免费一区二区三区 | 国产午夜亚洲精品不卡 |