[Tutor] Need to be pointed in the right direction for fileorganisation.

Alan Gauld alan.gauld at btinternet.com
Sat Jul 25 10:23:41 CEST 2009

"Mac Ryan" <quasipedia at gmail.com> wrote

> While I am working my way up to a more pythonic and cleaner style in
> the code, one thing that I have very confused ideas about is how I
> should organise my code, in terms of classes and files.

I don't think there is any definitive answer.

- Put reusable components into modules.

- Don't necessarily create a module per class, but rather gather 
  related classes into a single module.

- Build modules "bottom up" so that depenedencies tend to 
  go one way, with higher level modules importing lower level ones.

Beyond that there are many different approaches to organisation.
They all have strengths and weaknesses.

The good news is that Python is such a high level language 
that you rarely have projects with so many modules that you 
need to create sophisticated directory structures. Usually 
everything can fit in one project folder. (Zope, Django etc being 
good examples of exceptions! :-)

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list