You can simply run them on the terminal inside a file bash
. To do this, create an extension file sh
and include commands to run the extension files py
one after the other. Finally, go to the terminal and turn: bash meuarq.sh
Example:
Python file 1:
#primeiro programa extensão py
print('Hello world!')
Python file 2:
#segundo programa extensão py
print('Hello world again!')
Bash file:
#!usr/bin/bash
python python_program1.py
python python_program2.py
In the terminal:
bash meuarq.sh
Output:
Hello world!
Hello world again!
Follow alternative ways to run both files:
Concomitant:
#!usr/bin/bash
python python_program1.py &
python python_program2.py &
Conditional 1 (spins the second only if the first spins successfully):
#usr/bin/bash
python python_program1.py && python python_program2.py
Conditional 2 (only rotate the following if the previous one fails):
#usr/bin/bash
python python_program1.py || python python_program2.py
Important: both conditions accept chaining
Alternatively, you can use the functions, variables and objects created in the files programa1.py
and programa2.py
in another program. For this, just put these files in the folder in which you are working and import them as modules:
from programa1 import *
from programa2 import *
What is your operating system?
– Lucas
The system is Linux
– JB_
What is a "VPS that doesn’t allow parallelism"? VPS is "Vrtual Private Server - it’s a virtual machine - as you always have root access inside it, you can run as many processes as you want in parallel. (may have only 1 core, but can trigger multiple processes in parallel and let the operating system turn around)
– jsbueno
It has only one core, I did it plus the processor Ram arrived at 100% and killed all VPS processes.
– JB_