Background
Below, I detail two different ways of running Python files - I am confused about the difference between them.
- Running the Python file as an executable.
To run a Python file as an executable, I must first set a shebang in my file (# /usr/bin/env python3
), then run $ chmod +x filename.py
at the command line, then run $ ./filename.py
at the command line to execute the file.
- Running the Python file through the
python3
command line command.
To run a Python file through the python3
command, I open my command line and run $ python3 filename.py
.
My Question
I understand that, when running the Python file as an executable, the shebang directs the computer to launch the (in this case) python3
interpreter which will interpret the subsequent code in the file and therefore run the file. When running the file through the python3
command, I understand that this is just another way of directing the computer to launch python3
to interpret the code in the file. To me, these two techniques therefore seem identical.
Am I missing something? What's the difference, if any, between these two ways of running a Python file?