coupling python scripts

S

sandercaerteling

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?

Many thanks!
Sander
 
S

Steven D'Aprano

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top