2 ответов
+ 7
#!/usr/bin/python3 is a shebang line.
A shebang line defines where the interpreter is located. In this case, the python3 interpreter is located in /usr/bin/python3. It could be a bash, ruby, perl or any other scripting languages' interpreter. The operating system does not know it's a python script if you set the execution flag on the script and run it like ./script.py, unless you run it like python3 script.py or set the shebang line.
You can use /usr/bin/env python3 for portability across different systems if they have the language interpreter installed in different locations.
+ 1
the shebang line is used by linux operating systems to indicate what interpreter should be used to execute the script.
on Windows it is ignored, as an alternative mechanism, the script interpreter is associated with the file extension.
So,
On Windows you could run:
myScript.py
but would have to specify the interpreter if you change the file extension:
python myScript.txt
Whereas on Linux with the shebang line and execution permission,the file extension does not matter.