Prepend #! /usr/bin/python with your script. Run the following command in your terminal to make the script executable: chmod +x SCRIPTNAME.py. Now, simply type ./SCRIPTNAME.py to run the executable script.
How do I write a Python program in Linux terminal?
Python Programming From the Command Line
Open a terminal window and type ‘python’ (without the quotes). This opens python in interactive mode. While this mode is good for initial learning, you may prefer to use a text editor (like Gedit, Vim or Emacs) to write your code. As long as you save it with the .
How do I create a .PY file in Terminal?
Then, open the terminal and go to the directory where the code resides and run the script with a keyword python followed by the script name. To create the terminal.py file, use vim in the terminal with the program name as vim terminal.py and paste the below code in it. To save the code, press esc key followed by wq! .