#/Bin/what command does python run?

Source: Internet
Author: User
# What command does binpython run? Please explain in detail... This is what I encountered when I was a beginner in Python. Why ~~~~~~~~~~~~~~ Hate without posture, please increase ~~ #/Bin/what command does python run? Please explain in detail...
This is what I encountered when I was a beginner in Python. Why ~~~~~~~~~~~~~~ Hate without posture, please increase ~~ Reply content: first of all, you have missed a character. Which of the following is true?

#! /Bin/python

To understand what this line is for, you must first understand the concept of "magic number.

Each type of file starts with a sequence of bytes that identifies the file type. This byte sequence is called "magic number ".

Like a script in unix, this magic number is "#! ".The name of this magic number is "Shebang ".


When loading a file, the file interpreter of the operating system must first determine the file type, and then load a specific file interpreter to interpret the file. The basis for determining the file interpreter of the operating system is to look at the magic number.

So, when you see "#! ", The file interpreter of the operating system knows that this is a" script ".

Which script interpreter is used? It continues reading.

The result shows/bin/python.

That is to say, we need to use an interpreter named "python" in the/bin/python path to explain this file.

Therefore, the file interpreter of the operating system loads the python interpreter. Then the file interpreter task of the operating system is completed.

After the python interpreter is loaded and run, it will explain the file by itself.

At this time, it will see the first line :#! /Bin/python

It recognizes the starting line # As the mark marking the beginning of the comment line, so it considers this as a line of comment and skips it directly.
Then begin to execute the subsequent real python commands.

In summary, this line is interpreted in different forms by two levels of interpreters. This is a line of comment!
Add it after! Is the interpreter definition. When you run a script on a linux/unix system, tell the system what interpreter is used to run the script.
For example, if you execute a script

$ ./script
#! /Bin/python is not a command. It defines the location of the Python interpreter. Is to tell the system where to find the Python interpreter for this script.
For example ,#! /Bin/python3 defines the position of python3.
I usually write like this ,#! /Use/bin/env python
This allows the system to help find the Python interpreter, which can be used in multiple systems. What teaching materials are you using? For another one, I don't need to read the book that didn't explain this sentence. I don't need to remind UNIX systems to use/bin/python to explain and execute this script.


head -1 abc.sh#! /bin/bash 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.