gpt4 book ai didi

python - Python 中的项目结构和文件实现

转载 作者:太空宇宙 更新时间:2023-11-04 06:29:08 28 4
gpt4 key购买 nike

我在掌握如何构建我的 Python 项目时遇到了一些麻烦。我读过jcalderone: Filesystem structure of a Python project并一直在查看 CouchApp 的源代码, 但我仍然感到很困惑。

我理解如何文件的结构,但我不理解为什么。如果有人可以详细介绍一下,或者可以向我解释一下,我会很高兴。简单介绍如何设置基本的 Python 项目,以及文件如何相互交互。

我认为这绝对是来自 C、C++、Erlang 等其他语言的人或以前从未接触过编程的人可以从中受益的东西。

最佳答案

name the directory something related to your project. When you do releases, you should include a version number suffix: Twisted-2.5.

不确定为什么不清楚。这似乎很明显。这一切都必须在一个目录中。

为什么东西必须在一个目录中?因为每个人都这么说,所以这就是原因。

create a directory Twisted/bin and put your executables there.

这就是 Linux 的工作方式。可执行文件位于 bin 目录中。将此特定目录放入 PATH 环境变量中变得很容易。

If your project is expressable as a single Python source file, then put it into the directory and name it something related to your project. For example, Twisted/twisted.py.

没错。您有/Twisted、/Twisted/bin 和/Twisted/twisted.py,其中包含您实际运行的代码。你还会把它放在哪里?

这没有“为什么”。您还能把它放在哪里?

If you need multiple source files, create a package instead (Twisted/twisted/, with an empty Twisted/twisted/init.py) and place your source files in it. For example, Twisted/twisted/internet.py.

这正是 Python 包的工作方式。它们是包含 __init__.py 文件的目录。本教程对此非常清楚。

put your unit tests in a sub-package of your package Twisted/twisted/test/.

您还会在哪里进行测试?严重地。没有“为什么?”对此。没有明智的选择。

add Twisted/README and Twisted/setup.py to explain and install your software, respectively

没错。你还会把它们放在哪里?再次。没有“为什么?”它们位于顶级目录中,因为——好吧——这就是目录的用途。它包含文件。

关于python - Python 中的项目结构和文件实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5033904/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com