[Tutor] modular program

Alan Gauld alan.gauld at btinternet.com
Sun Mar 1 18:10:21 CET 2009


"Daniele" <d.conca at gmail.com> wrote

> I'd like to write a python program which can be easily extended by 
> other
> people. Where can I find some "best practices" for writing modular 
> programs?

Try reading wikipedia.
Try looking under "modular", "coupling" and "cohesion"
You could also try "Frameworks"

> I thought about a txt file containing function calls that my program 
> will
> parse and execute in order, or is it better just to execute every 
> .py file
> in a certain "module" folder

Erm, I don't know what you mean by that bit?! :-)

A text file full of python functions is a module if you name it .py.
You can then import it and use the functins therein.

> I don't like this as modules could need to be executed in different
> moments

You don't normally execute modules, you use the executable
functions within modules. (Although in the strictest sense functions
are themselves a form of module.)

> Can any1 point me to a relatively simple program to look at?

You could look at the topic on modules and functins in my tutor.
Or you could read the case study topic which uses modules
Or if you can find the paper book version (in your local library?)
you can read the Games Framework chapter which describes
how to write a set of modules (using classes) that are explicitly
designed to be extended rather than used as-is.

HTH,

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




More information about the Tutor mailing list