coupling python scripts

Steven D'Aprano steve at REMOVETHIScyber.com.au
Mon Dec 19 12:55:05 CET 2005


On Mon, 19 Dec 2005 02:54:23 -0800, sandercaerteling wrote:

> Hi There!
> 
> I created a few python scripts and everything is working fine. But to
> make it easier to run the procedure i want to couple these scripts in
> one big script. Is there a possibility to do this, can I for example
> make a script dat 'calls' the other script in the right order?


Some variation on this should work:




*** script1.py ***

def do_stuff():
    print "Hello"

if __name__ == "__main__":
    # execute this when being called as a script
    do_stuff()



*** script2.py ***

def do_something_else():
    print "World"

if __name__ == "__main__":
    do_something_else()




Now write a new script:

*** master_script.py ***

import script1, script2
script1.do_stuff()
script2.do_something_else()



Or even simpler, since script1.py and script2.py are callable from the
command line, just create a shell script and let your shell handle it:

*** script.sh ***

script1.py
script2.py





-- 
Steven.




More information about the Python-list mailing list