0

I have few python ".py" files in my local system.

For example i have ".py" stored at location: "C:\Users\jack\Desktop\MyFiles"

my filenames are "my_prog1.py", "my_prog2.py" and ""my_prog3.py"

Now i want to write 4th Python script and execute all the above python script one by one in windows from the 4th python script.

Please guide me with the solution for above problem statement.

Thanks..!!

2

2 Answers 2

3

One way you could do it is by using imports.

Lets say you have a python script called test.py, and you have an another called test2.py, you can import test2 into test.py and run it from there. Although they would have to be in the same directory.

In your case since the 4th script will be running the other three, it would be like this.

import my_prog1
import my_prog2
import my_prog3

The other way to do this is by using the os module

import os

os.system('python my_prog1')
os.system('python my_prog2')
os.system('python my_prog3')
Sign up to request clarification or add additional context in comments.

Comments

1

Use the import keyword in the fourth Python file to import the files that you would want to run. It would run all the files.

import my_prog1
import my_prog2
import my_prog3

Make sure all the files, including the fourth file, is in the same directory, or else this won't work.

Comments

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.