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