zoukankan      html  css  js  c++  java
  • [译]Why do people write #!/usr/bin/env python on the first line of a Python script?

    If you have several versions of Python installed, /usr/bin/env will ensure the interpreter used is the first one on your environment's $PATH. The alternative would be to hardcode something like #!/usr/bin/python; that's ok, but less flexible. In Unix, an executable file that's meant to be interpreted can indicate what interpreter to use by having a #! at the start of the first line, followed by the interpreter (and any flags it may need). If you're talking about other platforms, of course, this rule does not apply (but that "shebang line" does no harm, and will help if you ever copy that script to a platform with a Unix base, such as Linux, Mac, etc).

    如果你的电脑安装了多个版本的Python,/usr/bin/env将会确保解释器第一个是你环境的$PATH,替代的方法使用像#!/usr/bin/python硬编码的方式也可以,只是不太灵活。

    在Unix系统中,在第一行用#!后面跟随解释器符号,来表明一个可是文件简要被什么解释器解释执行。

    如果你的话说的是其他平台的话,当然这些规则并不适用,(但是"shebang行"并没有坏处,而且如果你将此脚本拷贝到类Unix的系统(Linux,Mac等)时会非常有帮助。)

  • 相关阅读:
    Oracle数据库基础select语句用法
    Java中volatile的作用以及用法
    [Java]读取文件方法大全
    经典SQL语句大全
    js动态加载控件jsp页面
    JAVA中List、Map、Set的区别与选用
    表格java代码的相关知识积累
    解决JSP中文乱码问题
    SSH框架的简单学习—Structs学习
    float存储方式编程验证
  • 原文地址:https://www.cnblogs.com/everfight/p/stack_translate.html
Copyright © 2011-2022 走看看