I have some convenience python scripts in my path that I want to run by calling them directly, e.g. myscript.py argument1
. But the arguments won't show up in sys.argv
.
test.py
#!python3.5
import sys
print(sys.argv)
So when I call this little script directly I can not access the given argument via sys.argv
.
c:\Users\MrLeeh\bin>test.py hello
['C:\\Users\\MrLeeh\\bin\\test.py']
While when I call it explicitly with the python
command I can access my argument.
c:\Users\MrLeeh\bin>python test.py hello
['C:\\Users\\MrLeeh\\bin\\test.py', 'hello']
I ask myself what is the reason for this and how can I access the arguments when using a direct call. My python files are associated with py.exe
.
Maybe you have missed some registry configuration.
There is a registry saved in HKEY_CLASSES_ROOT\Python.File\shell\open\command:
[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command]
@="\"C:\\Python27\\python.exe\" \"%1\" %*"
The registry setting above adds the "%*" to pass all arguments to python.exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With