MacOS – Rights on file read write execute

macosterminal

I am logged in as "myuser" which is also the administrator of the computer.
I have a file on which I have the following rights:

-r--r--r--   1 myuser  staff  167 17 Feb 14:26 my_python.py

However, when I type in python my_python.py on the command line, I still can run the file. Don't I need execute (x) rights in order to do that?!

The only way I cannot run the file is when I change the rights to:

----------   1 myuser  staff  167 17 Feb 14:26 my_python.py

Best Answer

Python only requires the file contents to be read.

Recall that Python is an interpreted language and just processes the contents of that file, rather than executing it; python is the executable here! Therefore, calling the interpreter with the file as input/argument does not require other than read permissions (e.g.,python example.py).