python script interpreter

# Script on the first line! / Usr / bin / python explanation, the first line of the script language, only to Linux / Unix users apply this script to specify what the interpreter to execute.

There's sentence, after adding execute permissions, you can directly use ./ execution, or be wrong, because no python interpreter.

#! / Usr / bin / python is time to tell the operating system to execute the script, call the python interpreter in the / usr / bin.

#! / Usr / bin / env python This usage is intended to prevent the operating system the user will not have python installed in the default / usr / bin path inside. When the system sees this line, the first thing will be to find the installation path settings in the env python, and then calls the interpreter program under the corresponding path to complete the operation.

#! / Usr / bin / python equivalent to write dead python path.

#! / Usr / bin / env python would go looking for python directory environment settings, you can enhance the portability of code, we recommended such an approach.

Divided into two situations:

(1) If you call python script, use:

script.py Python
#! / usr / bin / Python is ignored, equivalent to comment

(2) If you call python script, use:

./script.py
#! / usr / bin / Python interpreter specified path

PS: shell script In the first line has a similar statement.

Published 75 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/zhengdong12345/article/details/103888158