#!/usr/bin/env python3 # sample-bom.py: a Python file that starts with a UTF-8 byte order mark (BOM), # the bytes EF BB BF, which some Windows editors add. # Free sample from 99helpers.com/file-types/py # # python3 sample-bom.py works: Python skips a UTF-8 BOM. # ./sample-bom.py fails on macOS and Linux: the file no longer starts # with #!, so the shell tries to run it as a shell # script and reports errors such as # "#!/usr/bin/env: No such file or directory". # Fix: save as "UTF-8" rather than "UTF-8 with BOM". from pathlib import Path first = Path(__file__).read_bytes()[:3] print("Starts with a UTF-8 BOM:", first == b"\xef\xbb\xbf") print("Python ran this file without complaint.")