如何组织一个Python项目? [英] How to organize a Python Project?
问题描述
我是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 Module
和PyDev 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屋!