Files application architecture

Diez B. Roggisch deets at nospam.web.de
Fri Sep 5 12:45:01 EDT 2008


Benjamin Watine schrieb:
> Hi,
> 
> I'm about to develop a small python application and I wonder how to 
> organize files in this application.
> I'm familar to java, so I'm tempted to use the same convention : 1 file 
> per class and 1 folders per package.
> 
> I know that packages doesn't exists in python, they are modules instead.

This is wrong. There are packages & modules in python.

http://docs.python.org/tut/node8.html

And please *don't* do put one class per module, as you would do in Java! 
Instead, group related classes into modules, breaking them up into 
several submodules if size or differences in usage suggest so.

> May I create specific module for each "group of class" ? My application 
> follow the MVC paradigm, so basically, I've a package Model, a package 
> View, and a package Controller.
> 
> So, what are best practices for organizing files and folders in a small 
> python project ?
> I've found PEP8 (http://www.python.org/dev/peps/pep-0008/) that gives a 
> lot of good hints on coding convention, but nothing about files 
> organization.

The MVC pattern is more important in terms of actual classes written, 
not so much regarding their distribution over a set of files. If you 
want, start with one big single module inside a application-naming 
package - or even no package at all. Split up if you need to.

Or just go for

<mypackage>/__init__.py
<mypackage>/model.py
<mypackage>/view.py
<mypackage>/controller.py


if you *must*.

Diez



More information about the Python-list mailing list