批评我的 Python 包结构

发布于 2024-12-06 14:35:29 字数 1099 浏览 0 评论 0原文

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

I'm in the process of finishing up a Python package I've been writing. However, before I release it I'd like to get some feedback on the overall structure of the package as well as the __init__.py file.

This should give an idea of what my __init__.py file looks like.

'''
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__()

This should give a decent idea of the overall package structure.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2024-12-13 14:35:29

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

You should use absolute imports instead of relative imports, e.g. import mypackage.mypath as mypath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文