Files application architecture

  • Thread starter Benjamin Watine
  • Start date
B

Benjamin Watine

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

Thanks in advance !

Ben
 
D

Diez B. Roggisch

Benjamin said:
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
 
B

Bruno Desthuilliers

Benjamin Watine a écrit :
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
http://dirtsimple.org/2004/12/python-is-not-java.html

: 1 file
per class and 1 folders per package.

Don't. This is a waste of time and a pain to maintain, and more over it
doesn't make any sense since Python doesn't force you to put everything
in classes.
I know that packages doesn't exists in python,

Did you actually read the doc ? While Python's packages are not the same
thing as Java's, they do exist.

http://docs.python.org/tut/node8.html#SECTION008400000000000000000
they are modules instead.
May I create specific module for each "group of class" ?

The usual way to get cohesive modules is indeed to group closely related
objects (classes, functions, etc) in a same module.
My application
follow the MVC paradigm, so basically, I've a package Model, a package
View, and a package Controller.

If your app is small, having _modules_ models, views and controllers
should be enough.
So, what are best practices for organizing files and folders in a small
python project ?

The best practice is to keep things simple, as usual.
 
B

Benjamin Watine

Bruno Desthuilliers a écrit :
Benjamin Watine a écrit :

Don't. This is a waste of time and a pain to maintain, and more over it
doesn't make any sense since Python doesn't force you to put everything
in classes.


Did you actually read the doc ? While Python's packages are not the same
thing as Java's, they do exist.

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


The usual way to get cohesive modules is indeed to group closely related
objects (classes, functions, etc) in a same module.


If your app is small, having _modules_ models, views and controllers
should be enough.


The best practice is to keep things simple, as usual.

Thank you all for your good advices and links. I'm new to python and I
have yet a lot of things to learn !

Now, I would like to take a look to a well coded wxPython application.
Could anybody indicate a project that I could take as reference for
standard python coding style ?

Regards,

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,371
Latest member
TroyHursey

Latest Threads

Top