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

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

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

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

      python:不同包下同名的兩個模塊和類

      python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)

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

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

        <tfoot id='xoair'></tfoot>

            <tbody id='xoair'></tbody>

              • <legend id='xoair'><style id='xoair'><dir id='xoair'><q id='xoair'></q></dir></style></legend>
                本文介紹了python:不同包下同名的兩個模塊和類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我已經開始學習python并編寫一個練習應用程序.目錄結構看起來像

                I have started to learn python and writing a practice app. The directory structure looks like

                src
                 |
                 --ShutterDeck
                    |
                    --Helper
                       |
                       --User.py -> class User
                    --Controller
                       |
                       --User.py -> class User
                

                src 目錄位于 PYTHONPATH 中.在另一個文件中,比如說 main.py,我想訪問兩個 User 類.我該怎么做.

                The src directory is in PYTHONPATH. In a different file, lets say main.py, I want to access both User classes. How can I do it.

                我嘗試使用以下方法,但失敗了:

                I tried using the following but it fails:

                import cherrypy
                from ShutterDeck.Controller import User
                from ShutterDeck.Helper import User
                
                class Root:
                  @cherrypy.expose
                  def index(self):
                    return 'Hello World'
                
                u1=User.User()
                u2=User.User()
                

                這肯定是模棱兩可的.我能想到的另一種(c++ 實現方式)方式是

                That's certainly ambiguous. The other (c++ way of doing it) way that I can think of is

                import cherrypy
                from ShutterDeck import Controller
                from ShutterDeck import Helper
                
                class Root:
                
                  @cherrypy.expose
                  def index(self):
                    return 'Hello World'
                
                u1=Controller.User.User()
                u2=Helper.User.User()
                

                但是當上面的腳本運行時,它給出了以下錯誤

                But when above script is run, it gives the following error

                u1=Controller.User.User()
                AttributeError: 'module' object has no attribute 'User'
                

                我無法弄清楚為什么會出錯?ShutterDeckHelperController 目錄中有 __init__.py.

                I'm not able to figure out why is it erroring out? The directories ShutterDeck, Helper and Controller have __init__.py in them.

                推薦答案

                您要導入包 __init__.py 文件中的 User 模塊,使其可用作屬性.

                You want to import the User modules in the package __init__.py files to make them available as attributes.

                所以在 Helper/__init_.pyController/__init__.py 中添加:

                So in both Helper/__init_.py and Controller/__init__.py add:

                from . import User
                

                這使模塊成為包的屬性,您現在可以這樣引用它.

                This makes the module an attribute of the package and you can now refer to it as such.

                或者,您必須自己完整導入模塊:

                Alternatively, you'd have to import the modules themselves in full:

                import ShutterDeck.Controller.User
                import ShutterDeck.Helper.User
                
                u1=ShutterDeck.Controller.User.User()
                u2=ShutterDeck.Helper.User.User()
                

                所以用他們的全名來稱呼他們.

                so refer to them with their full names.

                另一種選擇是使用 as 重命名導入的名稱:

                Another option is to rename the imported name with as:

                from ShutterDeck.Controller import User as ControllerUser
                from ShutterDeck.Helper import User as HelperUser
                
                u1 = ControllerUser.User()
                u2 = HelperUser.User()
                

                這篇關于python:不同包下同名的兩個模塊和類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                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 包)
                R, Python: install packages on rpy2(R,Python:在 rpy2 上安裝包)
                      <bdo id='1encF'></bdo><ul id='1encF'></ul>
                      <i id='1encF'><tr id='1encF'><dt id='1encF'><q id='1encF'><span id='1encF'><b id='1encF'><form id='1encF'><ins id='1encF'></ins><ul id='1encF'></ul><sub id='1encF'></sub></form><legend id='1encF'></legend><bdo id='1encF'><pre id='1encF'><center id='1encF'></center></pre></bdo></b><th id='1encF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1encF'><tfoot id='1encF'></tfoot><dl id='1encF'><fieldset id='1encF'></fieldset></dl></div>
                    • <legend id='1encF'><style id='1encF'><dir id='1encF'><q id='1encF'></q></dir></style></legend>

                      1. <tfoot id='1encF'></tfoot>

                            <tbody id='1encF'></tbody>

                          <small id='1encF'></small><noframes id='1encF'>

                          主站蜘蛛池模板: 欧美在线日韩 | 免费av手机在线观看 | 精品二区视频 | 国产情侣一区 | 二区久久 | 日韩在线欧美 | 亚洲天堂免费 | 日韩成人在线观看 | 中文字幕一区二区三区日韩精品 | 中国大陆高清aⅴ毛片 | 狠狠综合久久av一区二区小说 | 韩日视频在线观看 | 欧美精品网站 | 一a一片一级一片啪啪 | 在线视频一区二区 | 久久国产精品视频 | 一区二区精品 | 在线91 | 成年人的视频免费观看 | 日韩中文字幕 | 日韩中出 | 欧洲视频一区二区 | 欧美一区二区在线 | 精品一区二区三区四区五区 | 免费观看黄网站 | 视频一区二区三区中文字幕 | 久久草在线视频 | 97超碰免费 | 中文av电影| 日韩精品视频在线观看一区二区三区 | 成人午夜免费网站 | 九色在线视频 | 一区二区三区视频在线免费观看 | 久久久精品日本 | 中文字幕91av | 日本久久精 | 狠狠做深爱婷婷综合一区 | 国产黄色在线观看 | 成人精品视频 | 国产欧美日韩二区 | 亚洲精品在线播放 |