4

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.

0

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.