3 ms·
> Firstly, Linux seems to have no concept of "associated program", so you can never "just" call .py file, and let the shell to know to use python to execute it.
by rascul 2y ago
> Firstly, Linux seems to have no concept of "associated program", so you can never "just" call .py file, and let the shell to know to use python to execute it. Sure, you can chmod +x to the script, but then you have to add a shebang line directly to the script itself, which I always feel uncomfortable since it's hard-coded (what if in future I don't want to execute my .py script with `/usr/bin/python` but `/usr/bin/nohtyp`?).
Might be you could use binfmt_misc for that.
https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html https://www.kernel.org/doc/html/latest/admin-guide/binfmt-mi...
- MarkSweep 2y agoHere is an article about using binfmt_misc to make .go files executable. I assume something similar could be done for python: https://blog.cloudflare.com/using-go-as-a-scripting-language-in-linux/ https://blog.cloudflare.com/using-go-as-a-scripting-language...
- o11c 2y agobinfmt_misc is only useful for when a fileformat does not allow shebangs
- rascul 2y agoOr if you don't want to use shebangs as mentioned.