What does the symbol "#!" mean in Python?
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
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 with xyz
, will run it using that interpreter, similar to:
/usr/local/bin/python3 xyz
This is not a python specific notion, see http://en.wikipedia.org/wiki/Shebang_(Unix)
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 be program-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 in python3
being looked up in the current PATH which is much more portable.
That is not python-specific but is called Shebang and tells the operating system with which program to run this script.
UNIX Shebang? See http://en.wikipedia.org/wiki/Shebang_(Unix)
. The space between !
and the first /
probably shouldn't be there.
精彩评论