Categories
Python Answers

How to run a Python file in another Python file?

Spread the love

Sometimes, we want to run a Python file in another Python file.

In this article, we’ll look at how to run a Python file in another Python file.

How to run a Python file in another Python file?

To run a Python file in another Python file, we can use the subprocess.call method.

For instance, we write

from subprocess import call

call(["python", "your_file.py"])

to call call with a list with the command and arguments to run the your_file.py Python script in the same directory as the current script.

Conclusion

To run a Python file in another Python file, we can use the subprocess.call method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *