如何组织一个Python项目? [英] How to organize a Python Project?

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

问题描述

我是Python的新手,正在启动一个小型项目,但是我对如何以"Python方式"组织文件夹有一些疑问.

I'm new to Python and I'm starting a mini Project, but I have some doubts on how to organize the folders in the "Python Way".

我在开发环境中使用PyDev,创建新项目时会创建一个名为src

I'm using PyDev in my Development Environment, and when I create a new project a folder is created called src

+ src

现在,在PyDev中,我可以创建Pydev ModulePyDev Package

Now, in the PyDev, I can create Pydev Module and PyDev Package

我需要通过以下方式组织我的项目:

I need to organize my Project in the following way:

+ Indicators
    - Moving_averages.py
    - Stochastics.py
+ Strategies
    - Moving_averages_cross.py
- example.py

如何根据模块和软件包进行组织?模块和软件包的含义是什么?

How can I organize this in terms of Modules and Packages? What is the meaning of Modules and Packages?

最好的问候,

推荐答案

Package基本上是一个文件夹,该文件夹下带有__init__.py文件,通常还包含一些Modules,其中Module是*.py文件. 它主要与import有关.如果将__init__.py添加到指标中,则可以使用:

A Package is basically a folder with __init__.py file under it and usually some Modules, where Module is a *.py file. It has to do with import mainly. If you add __init__.py to Indicators you can use:

from Indicators.Stochastics import *

from Indicators import Stochastics

顺便说一句,我建议将模块/软件包名称保持小写.它不会影响功能,但更像是"pythonic".

By the way, I would recommend to keep module/package names lowercase. It does not affect functionality but it's more "pythonic".

这篇关于如何组织一个Python项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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