python - 批评我的 Python 包结构

标签 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

最佳答案

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

关于python - 批评我的 Python 包结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7577651/

相关文章:

python - Python中符号函数的数值积分

python - 阈值图像数组和渲染的有效方法 - Python/NumPy/OpenCV

python - 无法打印出请求的文本?

python - 如何以编程方式设置全局(模块)变量?

r - 在 R 包中分配锁定变量

python - Anaconda 包错误,启动 Sublime Text-3

module - 模块和共享库之间的区别?

ruby - 使模块继承自 Ruby 中的另一个模块

Perl:静态方法与包方法

python - 如何使用 python 的性别化包来处理大数据集?