Reputation: 1971
I have three python scripts: schedule.py
, script1.py
and script2.py
.
I want to start running script1.py
and script2.py
by schedule.py
. Moreover, I want to run script1.py
first, and then activate script2.py
after script1.py
has finished.
I found a similar question here, but I think this person wants to do this via Terminal, or a similar program. I want to do this via Python.
For the moment, I have,
import script1.py
import script2.py
How do I go about?
Upvotes: 1
Views: 6037
Reputation: 224
Well you can use the code you have in these scripts by invoking
script1.whatever_function_you_have
Just treat them like modules. No different than importing os, sys, or any other module you create. If you want to run the entire py script, then you can always create a main loop at the bottom of the file to run the code. For example:
import script1
import script2
if __name__ == '__main__':
script1.foobar()
script2.goobat()
This would be placed at the bottom of the schedule file and you list what code you want to run and it will run it.
Upvotes: 1
Reputation: 616
I would recommend wrapping your python scripts (script1.py, script2.py) within their own functions and then calling those functions in order from the schedule.py
Upvotes: 1