Hacker News new | ask | show | jobs
by rascul 733 days 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-mi...

2 comments

Here 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...

binfmt_misc is only useful for when a fileformat does not allow shebangs
Or if you don't want to use shebangs as mentioned.