[Python-au] Calling two Python Scripts form another scipt

Duane Hennessy duaneh at connexus.net.au
Sat Nov 22 08:48:55 CET 2003


Sophie,
    If the exec function is not working for you, you could try importing 
the scripts first. This looks a little verbose but hey it works and I 
use it all of the time.

Import the 'ihooks' module. (you could use the 'imp' module but I found 
it slightly fickle to use and 'ihooks' implements imp well without the 
headaches).
Find the scripts using ihooks and then load them (this is good as you 
can test to see if the scripts are there). Code as follows.

### code starts here ###

import ihooks

# load the module loader
mdl = ihooks.BasicModuleLoader()

# look for the script as a module
myScript = mdl.find_module('Script1','C:\\Temp')

# load the script through the module loader
scriptToRun = mdl.load_module('Script1',myScript)

# execute the code
scriptToRun.main()

### code ends here ###

Just for fun you could pass a list of script names to run and iterate 
through them, loading and executing one after the other.

Hope this helps, sometimes I find the documentation on Python and the 
list of examples somewhat lacking in quality.

Duane Hennessy
Cleveland, Tropical Queensland, Australia.








More information about the python-au mailing list