[Tutor] functions in other files, executing
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 21 Oct 2002 11:31:17 +0100
> basically, every module has to be in it's own directory,
> because they each have extra bits of data in separate
> files with them.
Its quite common for a module to depend on some
kind of external configuration data. Applying the
old CS maxim of "You can do it with one more level
of indirection" this is normally tackled by having
a config file that is read at startup by the module.
The config file then includes the references to the
real data - in your case the full path to the needed
icons...
Now when you want to reuse the module in another
project you just create a new config file pointing
at the new projects icons... Now you can keep the
modules and config files in the same folder or,
probably better, keep the modules together but put
the module file in a project specific directory
specified by an environment variable say. Then each
project can have its own environment variable and
its own folder of config files....
If you need more control still then you can create
a module init function that takes the config file
path as a parameter. Then users can run several
instances at the same time(on different projects
say) for the slight penalty of having to call the
init function:
import foo
foo.init('some/path/here/')
Like I said, "You can do it with one more
level of indirection...."
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld