Sistu Srikanth
Sistu Srikanth

Reputation: 5

How to run multiple scripts from a script in python

I have 3 Python scripts, script1, script2 and script3 in a folder. I want to run script2 and script3 using script1. How can I do this?

Upvotes: 0

Views: 261

Answers (3)

Felu da
Felu da

Reputation: 1

You can also use os.system:

os.system("script2.py")
os.system("script3.py")

Upvotes: 0

Rob
Rob

Reputation: 538

In script1 you need to import script2 and script3:

At the top of script1:

import script2
import script3

To run a function from script2 for example:

script2.function()

You may also need to add a blank file called __init__.py in the same directory as the scripts, so that python can see that the directory is a library.

Upvotes: 1

sachin saxena
sachin saxena

Reputation: 976

You can use

    execfile("script2.py")
    execfile("script3.py")

or

    subprocess.call("script2.py")
    subprocess.call("script3.py")

Upvotes: 1

Related Questions