This question is asking why specifying the python interpreter before the path to a python script makes the script run even when it is UTF-8 BOM encoded.
My python script /home/osmc/python/test3.py
is executable and has the shebang #!/usr/bin/python
at the start of the script. I run the script in OSMC which is a linux OS based on Debian. It uses the /bin/bash shell.
I understand when you encode a python script using UTF-8 (WITH BOM) the Byte Order Mark (BOM) is a signature inserted into the start of the script and this prevents the linux system from correctly reading the shebang line. The result is it doesn't know what interpreter to use to run the script so it won't.
Hence if the script is encoded in UTF-8 (WITH BOM) it won't run from the command line if run like this:
# /home/osmc/python/test3.py
However it will run like this:
# /usr/bin/python /home/osmc/python/test3.py
My question:
Is this because the python interpreter automatically detects the byte order mark at the start of the python script and ignores it? Is the python interpreter able to detect how the python script is encoded and thus knows to ignore the BOM?