There are two ways to execute a python file using a terminal
Mode one: Command line mode
Method Two: Python interactive mode
Command-line mode
In command-line mode, a. py file is executed, and a Python file is written in the editor, saved in the. py format, and executed in the terminal. Be sure to note that the current location is located under the location of the. py file when executing the. py file at the terminal.
Here is the direct execution of the one.py file via Python one.py, the error display is to find this file.
So the first step should be to enter the directory of this file, and then execute the. py file, as follows
Note: If you do not know the absolute path of this file, you can drag the file into the terminal, the terminal will show the path of the file
Python interactive mode
Executing the. py file using Python interactive mode first to enter Python interactive mode in the terminal
Enter the interactive mode: Enter Python in the terminal, carriage return, show the following is successfully entered the interactive mode, prompt is >>>
Exit Interaction Mode: Enter exit () in terminal, return, you can exit the current interactive mode
In Python interactive mode can be directly written Python program, but the program has not been written to save, suitable for beginners to practice practiced hand
A Python program can be written after the >>> prompt
Using a terminal to execute a python program