Python Script Runner
- Starting A Python Script
- Python Script Runner Online
- Learn Python Script
- Free Python Scripts
- Python Script Runner Windows
In this guide, I’ll show you how to run one Python script from another Python script.
- Conclusion – running a Python script from the terminal in your Raspberry Pi In this tutorial you’ve seen how to configure your Raspberry Pi so that you can run a Python script from the terminal. When you start with Raspberry Pi and Python 3, it’s good to use the Thonny Python IDE at first, which will allow you to focus on learning Python.
- Python is a practical, feature-rich language with extensive library support that enables you to create custom scripts. Table 1 outlines the Python versions available on devices running Junos OS and devices running Junos OS Evolved and notes the release in which support for that version was added or removed for certain types of scripts.
Python is a practical, feature-rich language with extensive library support that enables you to create custom scripts. Table 1 outlines the Python versions available on devices running Junos OS and devices running Junos OS Evolved and notes the release in which support for that version was added or removed for certain types of scripts.
More specifically, I’ll review the steps to:
- Run one Python script from another
- Call a specific variable from one Python script to another
But before we begin, here is a simple template that you may use to run one Python script from another (for Python scripts that are stored in the same folder):
Steps to Run One Python Script From Another
Step 1: Place the Python Scripts in the Same Folder
To start, you’ll need to place your Python scripts in the same folder.
For example, I placed two Python scripts (called python_1 and python_2) in the same folder as below:
The ultimate goal is to run the python_2 script from the python_1 script.
Step 2: Add the Syntax
Next, add the syntax to each of your scripts.
For instance, I added the following syntax under the python_1 script:
Where:
- The first line of ‘import python_2’ in the python_1 script, would call the second python_2 script. Whenever you want to run one Python script from another, you’ll need to import the exact name of the Python script that you’d like to call
- The second part of the code simply prints the expression of ‘what are you up to?’
Now let’s add the syntax under the python_2 script:
In this case, the expression of ‘hello world’ would be printed when running the second script.
Note that you must first save the syntax that was captured in the python_2 script before calling it from another script:

Step 3: Run One Python Script From Another
Now you’ll need to run the script from the python_1 box in order to call the second script:
Notice that the results of the python_2 script would be displayed first, and only then the results of the python_1 script would be displayed:
Call a Specific Variable from One Python Script to Another
Let’s now see how to call a specific variable (which we will call ‘x’) from the python_2 script into the python_1 script.
In that case, you’ll need to edit the syntax under the python_1 script to the following:
So the python_1 script would now look like this:
Next, assign a value (e.g., ‘hello world’) to the x variable in the python_2 script:
Starting A Python Script
So the python_2 script would now look like this:
Don’t forget to save the changes in the python_2 script:
Finally, run the syntax from the python_1 script:
Python Script Runner Online
The ‘hello world’ expression would now get printed:
Interaction of Variables from the Two Scripts
In the final section of this guide, you’ll see how variables from the two scripts may interact.
For example, let’s suppose that the python_1 script has the variable of y = 2, while the python_2 script has the variable of x = 5. The goal is to sum those two variables and display the results.
First, modify syntax under the python_1 script to the following:
Your python_1 script would now look like this:
Then, change the syntax in the python_2 script to:
So your python_2 script would now look like this:
Learn Python Script
As before, don’t forget to save the changes in the python_2 script:
Free Python Scripts
Finally, run the syntax from the python_1 script:
Python Script Runner Windows
You’ll then get ‘7’ which is indeed the sum of the two variables: