Reputation: 18572
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
Upvotes: 11
Views: 11444
Reputation: 14637
UNIX Shebang? See http://en.wikipedia.org/wiki/Shebang_(Unix)
. The space between !
and the first /
probably shouldn't be there.
Upvotes: 2
Reputation: 18695
That is not python-specific but is called Shebang and tells the operating system with which program to run this script.
Upvotes: 2
Reputation: 318598
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.
Upvotes: 7
Reputation: 38392
This is not a python specific notion, see http://en.wikipedia.org/wiki/Shebang_(Unix)
Upvotes: 8
Reputation: 882156
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
Upvotes: 18