[Tutor] Python module structure & directories

Alan Gauld alan.gauld at btinternet.com
Thu Nov 25 02:23:21 CET 2010


"Judy Chen" <jgc617 at yahoo.com> wrote

> I am very new to Python, I worked on C/C++ before.
> I would like to know is it a good practice to put Python development 
> code under
>
> ../src/UI/foo.py
> ../src/businesslogic/bar.py, etc.

Thats fine, especially if its a big project.
src means source code and python is a type of source just as C is.

> or should we eliminate "src' directory since it is not pythonic, or 
> it very C/C++ like.

Who says its not pythonic?
src is a perfectly common name to use on Unix type systems for all 
types
of source code.

> I was told that the above directory/file structure does not apply to
> Python, since Python's source code are objects.

The source code is not really an object but becaiuse you can import
any python file as a module, and modules are objects (once they are
loaded) you might get away with saying that. But really, python source
files are no different to any other source files when it comes to 
organising
your file system for a project.

> Are there any standard for how Python source code to be structured?

Not that I'm aware of. There are some standards for how to create
packages which might restrict things a little but oprovided you have
your PYHONPATH set up tio find the modules all should be well.
And you might want to create a build script that moves the modules
from src to lib in the production file system. But on a project, 
especially
one  with multiple programming languages, having all source files in
one place is a definite plus IMHO.

Another thing to do would be take a look at some of the Python 
projects
on Sourceforge - DIA for example. See how they structure their code.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list