Python Script does not accept sys.argv on Windows

I have two Windows computers and I just found that on one of them, if I ran python code directly, for example:

test_args.py input1 input2 

Python does not recognize the input I entered, but this works:

 python test_args.py input1 input2 

I tried the code:

 import sys print 'Number of arguments:', len(sys.argv), 'arguments.' print 'Argument List:', str(sys.argv) 

And the first method (test_args.py) returns:

 Number of arguments: 1 arguments. Argument List: ['D:\\Test\\args\\test_args.py'] 

While the sceond path (python test_args.py input1 input2) returns:

 Number of arguments: 3 arguments. Argument List: ['D:\\Test\\args\\test_args.py', 'input1', 'input2'] 

Any idea that this could happen? This problem occurs only on one of my computers, both have the same version of Windows.

Thanks!

SOLVE:

I search the regedit keyword "python" and find that the two keys are missing% * after "C: \ Python27 \ python.exe" "% 1":

Computer \ HKEY_CLASSES_ROOT \ Applications \ python.exe

Computer \ HKEY_CLASSES_ROOT \ py_auto_file shell \ open \ command \

And .py is connected to py_auto_file, although I tried to connect .py Python.File

Changing the two keys fixed this problem, thanks!

+8
source share
1 answer

Check what is the association of * .py files on these two computers. The script can be executed by various Python interpreters.

+1
source

All Articles