簡體   English   中英

批判我的Python包結構

[英]Critique my Python Package Structure

我正在整理我一直在寫的Python包。 但是,在發布它之前,我希望獲得有關程序包以及__init__.py文件的總體結構的一些反饋。

這應該讓我了解__init__.py文件的外觀。

'''
A docsting describing the package.
'''

__author__     = myname
__copyright__  = mycopyright
__credits__    = listofcredits
__license__    = mylicense
__version__    = 0.0
__maintainer__ = me
__email__      = myemail
__status__     = indevelopment

# This contains a module with directories as strings (for file reference)
import mypath

# some modules
import this
import that

# some gui widget classes
from windowmodule import windowwidget
from widgetmodule import someguiwidget
from someothermodule import someotherguiwidget, andanotherguiwidget

def __demo__ () :
    # a demo of the package

if __name__ == '__main__' :
    __demo__()

這應該給整體包裝結構一個好主意。

mypackage/
    mypath.py
    __init__.py
    license.txt
    readme.txt
    modules/
        this.py
        that.py
    windows/
        windowmodule.py
    widgets/
        widgetmodule.py
    images/
        imagefiles.whatever
    tools/
        tools.py

您應該使用絕對導入而不是相對導入,例如, import mypackage.mypath as mypath

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM