The difference between python--#!/usr/bin/env Python and #!/usr/bin/python--reprint

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/wh_19910525/article/details/8040494

wh_19910525

The first line of the scripting language is to point out that you want the code in your file to run it with whatever executable program it is, so simple

#!/usr/bin/python is to tell the operating system to execute the script, call/usr/bin under the Python interpreter;
#!/usr/bin/env python is used to prevent operating system users from not loading Python into the default/usr/bin path. When the system sees this line, it will first find the Python installation path in the env settings, and then call the interpreter program under the corresponding path to complete the operation.
#!/usr/bin/python equivalent to writing dead python path;
#!/usr/bin/env Python will go to the environment settings to find the Python directory, recommend this writing

Here are some personal tips:

#!/usr/bin/env python # behind! There must be no spaces before, otherwise this sentence will be recognized as a comment

When the script is not recognized for execution with the Python interpreter, the system default script interpreter is used and an error is encountered.

For example:

Lnphonedemacbook-pro:desktop lnphone$./test.py. 5: syntax error near unexpected token ' ('5: ' width = input (') '

The difference between python--#!/usr/bin/env Python and #!/usr/bin/python--reprint

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.