0

Python Comment Header

so when i download python script from internet, they always put #/usr/bin/python env is there any mean for this? or this is just normal comment?

17th Dec 2017, 6:12 AM
Kevin AS
Kevin AS - avatar
2 Antworten
+ 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.
17th Dec 2017, 6:17 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 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.
17th Dec 2017, 12:25 PM
ifl
ifl - avatar