It's common on Unix-like systems to have the first line of a script include a special comment, #!
, called a shebang. This allows the program loader to identify which interpreter should be used to run the program. Shebangs have an additional purpose of conveniently documenting at the top of a file whether the Python code therein is Python 2 or Python 3.
The exact details of your shebang command depend on the location of Python on your system. Typical Python 3 shebangs use the Unix env
program to locate Python 3 on your PATH
environment variable, which importantly is compatible with Python virtual environments:
#!/usr/bin/env python3
On Mac or Linux, we must mark our script as executable using the chmod
command before the shebang will have any effect:
$ chmod +x words.py
Having done that, we can now run our script directly:
$ ./words.py http://sixty-north.com/c/t.txt