How to organize a Python Project?

André picture André · Mar 1, 2011 · Viewed 62.6k times · Source

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".

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

+ src

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?

Best Regards,

Answer

Botond Béres picture Botond Béres · Mar 1, 2011

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 *

or

from Indicators import Stochastics

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