views:

106

answers:

1

I use python to patch system settings of linux systems distributed with partimage. I want to have the following python script structure:

/patch.d/
    10_patch_netwok.py
    20_patch_hostname.py
    ...
    50_patch_software_xyz.py

InitSystem.py

The InitSytem.py should run the python scripts in /patch.d folder. Following my idea (brainstorm):

files = glob.glob("patch.d/*.py")
files.sort()
for file in files:
    execfile(file, ...)

What's the recommend way to load python scripts and run them from another python script?

+1  A: 

Python scripts are also python modules, so the best way to load and run them is to simply import them using

__import__('some_module')

This will mean that they run in the same process though. If this is undesirable, then your options would be to use the multi-threading or multi-processing support in python to run each script in a different thread/process to avoid interference, or to use the os.subprocess module to do system calls that run the scripts.

workmad3