1

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

Just did a quick google search and found this as well: stackoverflow.com/questions/12603482/… you might want to look a little harder next time when researching for your answers as you will invoke plenty of downvotes for lack of trying. Just a helpful tip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.