符号“#!”代表什么?在 Python 中是什么意思?
这行代码是什么意思?没有它,我的python3 http服务器无法理解并让浏览器下载一个空的.py文件(取决于.py文件的链接)
#! /usr/local/bin/python3
What does this line of code mean? Without it, my python3 http server can't understand and let the browser download an empty .py file (depend on the link to the .py file)
#! /usr/local/bin/python3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这不是 Python 的东西,它是一个 hashbang (或 shebang)行,指示哪个解释器应该处理该文件。
规则各不相同,但最简单的形式是,当使用
xyz
从命令行运行时,将运行名为xyz
的文件(包含作为第一行)它使用该解释器,类似于:It's not a Python thing, it a hashbang (or shebang) line which indicates which interpreter should process the file.
The rules vary but, in its simplest form, a file with the name
xyz
(containing that as the first line), when run from the command line withxyz
, will run it using that interpreter, similar to:这不是 python 特定的概念,请参阅 http://en.wikipedia.org/wiki/Shebang_( Unix)
This is not a python specific notion, see http://en.wikipedia.org/wiki/Shebang_(Unix)
这是 shebang/hashbang 行和 Linux/UNIX 的东西,根本与 Python 无关。
执行该文件时,内核将看到
#!
魔法并使用其后面的任何内容来执行脚本。由内核启动的实际程序将是program-from-shebang script-file-path [script-args]
请注意,包含
... 通常不是一件好事。 /local/...
路径,而是使用例如#!/usr/bin/env python3
这将导致在当前 PATH 中查找python3
这更加便携。It's the shebang/hashbang line and a Linux/UNIX thing, not Python-related at all.
When executing the file, the kernel will see the
#!
magic and use whatever comes after it to execute the script. The actual program that gets launched by the kernel will beprogram-from-shebang script-file-path [script-args]
Note that it's usually not a good thing to include a
.../local/...
path but rather use e.g.#!/usr/bin/env python3
which will result inpython3
being looked up in the current PATH which is much more portable.这不是特定于 python 的,但称为 Shebang 并告诉操作系统使用哪个程序来运行此脚本。
That is not python-specific but is called Shebang and tells the operating system with which program to run this script.
UNIX 谢邦?请参阅
http://en.wikipedia.org/wiki/Shebang_(Unix)
。!
和第一个/
之间的空格可能不应该存在。UNIX Shebang? See
http://en.wikipedia.org/wiki/Shebang_(Unix)
. The space between!
and the first/
probably shouldn't be there.