批判我的Python包结构

时间:2011-09-28 02:23:20

标签: python module package init

我正在完成我一直在编写的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

1 个答案:

答案 0 :(得分:1)

您应该使用绝对导入而不是相对导入,例如import mypackage.mypath as mypath