Daniele wrote: >> From: W W <sri...@gmail.com> >> Subject: Re: [Tutor] modular program > >>> Where can I find some "best practices" for writing modular programs? >>> 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 (I don't like this as modules could need to be >>> executed in different moments)? > >> You can pretty much take a look at any of the modules in your python >> library directory. In the case of my linux box, that's >> /usr/lib/python2.5/ > > I'm sorry, I've realized I didn't explain my needs at all. > I was a little influenced by drupal's definition of modules, which is > completely different from python's. > With module here I meant plug-in or extension: a piece of code written > by someone else that can be easily (and automaticallly) integrated > into my program. > My program must provide the posibility to be extended without editing > its code, just like mozilla's add-ons.
It heavily depends on the design of the main program. The simplest way to have a plug-in system is probably having user writes python modules which your program will import and call a certain agreed function. for example mainprogram.py: um_name = raw_input('Enter usermodule's filename: ') um = __import__(um_name) um.run() usermodule.py: def run(): # do initializations required to install the module _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor