Is there any way to disable double click for .py
files but still be able to run them from cmd/batch?
I believe the only solution for disabling double-click execution is to disassociate the .py
file extension from Python entirely. How you might go about that could be different depending on what Python distribution you have installed (for instance, with CPython from python.org, py.exe
is typically what manages Python script execution, rather than a direct Windows association between a given python.exe
and .py
files).
Regarding cmd
\batch execution, that would simply be e.g.:
C:\path\to\your\python.exe script.py option1 option2 ...
That is, double-click and cmd
\batch execution are completely separate, just as with non-py
files.
If you have a preferred version of Python available at the command line (e.g. as python
), then you could likely use that in place of the full path to python.exe
.
assoc .py=txtfile
- after that, doubleclicking opens them in notepad (if you didn't changeftype txtfile
). Note the output ofassoc .py
before, in case you want to revert it sometimes in the future..py
file), you can call your phyton script with a (dummy) parameter from the batchfile. By executing with a double-click, there are no parameters. So just check for parameters in your phyton script and exit, when there are none.