【问题标题】:Critique my Python Package Structure批评我的 Python 包结构
【发布时间】:2011-09-28 10:28:15
【问题描述】:

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

【问题讨论】:

标签: python module package init


【解决方案1】:

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

【讨论】:

  • ...为什么?这是个人喜好吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-13
  • 2014-03-27
  • 2021-07-16
  • 1970-01-01
  • 2011-02-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多