Home | About | Categories | All Tips & Tutorials

Learning Python3, System calls on Linux

ID: 222

Category: Python3

Added: 1st of December 2020

Views: 2,114

To make a system call from your Python script, for example displaying the current version of Python3 using the command python3 --version, we need to use the import os module, and use the os.system function

Create a new file named system_call.py and copy and paste the code below

#!/usr/bin/python3

import os
os.system('python3 --version')


Then enter the following command to make the Python script executable
chmod +x system_call.py


Then run the script by the entering the command
./system_call.py


If everything works correctly the current version of Python3 will be display in the terminal