On BSD'ish Unix systems, Python scripts can be made directly executable, like shell scripts, by putting the line
BSD类的 Unix系统中,Python 脚本可以像 Shell 脚本那样直接执行,只要在脚本文件开头写一行命令,指定文件和模式:
#! /usr/bin/env python
(assuming that the interpreter is on the user's PATH) at the beginning of the script and giving the file an executable mode. The "#!" must be the first two characters of the file. On some platforms, this first line must end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or Windows ("\r\n") line ending. Note that the hash, or pound, character, "#", is used to start a comment in Python.
(将用户路径通知解释器) "#!"必须是文件的前两个字符,在某些平台上,第一行必须以 Unix 风格的行结束符("\n")结束,不能用Mac("\ r")或Windows("\r\ n")的结束符。注意,"#"是Python中是行注释的起始符。
The script can be given a executable mode, or permission, using the chmod command:
脚本可以通过 chmod 命令指定执行模式和许可权。
$ chmod +x myscript.py