python项目的项目结构 [英] Project structure for python projects

查看:209
本文介绍了python项目的项目结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何工具可以为python特定项目生成项目布局,这与maven在Java项目中使用mvn archetype:generate所完成的工作非常相似.

Are there any tools which generate a project layout for python specific projects, much similar to what maven accomplishes with mvn archetype:generate for java projects.

推荐答案

这是个好消息:您不需要任何工具.您可以以任何需要的方式组织源代码.

It is the good news: you do not need any tool. You can organise your source code in any way you want.

回顾一下为什么我们在Java世界中需要工具:

Let recap why we need tools in the java world:

在Java中,您想预先生成目录,因为名称空间系统指示每个类必须位于反映该包层次结构的目录结构中的一个文件中.因此,您将拥有一个深层的文件夹结构. Maven对文件位置实施了一组额外的约定.您想拥有自动执行此操作的工具.

In java you want to generate directories upfront because the namespace system dictates that each class must live in one file in a directory structure that reflects that package hierarchy. As a consequence you have a deep folder structure. Maven enforces an additional set of convention for file location. You want to have tools to automate this.

其次,不同的人工制品需要使用不同的目标,甚至需要使用其他行家项目(例如,一个耳朵工程需要一些罐子和战争人工制品).有太多要创建的文件,您想拥有自动执行此操作的工具.

Secondly, different artefacts require use of different goals and even additional maven projects (e.g. a ear project requires a few jars and war artefacts). There are so many files to create you want to have tools to automate this.

复杂性使得像mvn archetype:generate这样的工具不仅有用.这几乎是必不可少的.

The complexity makes tools like mvn archetype:generate not just helpful. It is almost indispensable.

在python领域,我们只是在语言上没有这些复杂性.

In python land, we just do not have these complexity in the language.

如果我的项目很小,我可以将所有类和函数放在一个文件中(如果有意义)

If my project is small, I can put all my classes and functions in a single file (if it makes sense)

如果我的项目规模较大(LOC或团队规模),则以对您和您的同龄人有意义的任何方式将.py文件分组到模块中是有意义的.

If my project is of a bigger size (LOC or team size), it makes sense to group .py files into modules in whatever way makes sense to you and your peers.

最后,这是要在易于维护和可读性之间取得平衡.

At the end of the days, it is about striking a balance between ease of maintenance and readability.

这篇关于python项目的项目结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆