Why do people write #!/usr/bin/env python on the first line of a Python script?

后端 未结 21 1723
刺人心
刺人心 2020-11-21 06:16

It seems to me like the files run the same without that line.

21条回答
  •  一向
    一向 (楼主)
    2020-11-21 06:55

    Technically, in Python, this is just a comment line.

    This line is only used if you run the py script from the shell (from the command line). This is know as the "Shebang!", and it is used in various situations, not just with Python scripts.

    Here, it instructs the shell to start a specific version of Python (to take care of the rest of the file.

提交回复
热议问题