Python will not read sys.argv

user1024028 picture user1024028 · Nov 1, 2011 · Viewed 14k times · Source
    import sys

    print sys.argv[1]

hi,

this may seem very basic but I can't get Python to read in anything from the command line. thats the code above and what I type is:

    myfile.py helloworld

and what i get back is:

    IndexError: list index out of range

It seemed to work once for me but won't work any more, and I've tried uninstalling and reinstalling Python and it still doesnt work.

So my question is, am I doing anything wrong? or have I just broken Python?

Thanks for any help

Using: Windows 7 Python 2.7.2

Answer

Juuso Ohtonen picture Juuso Ohtonen · Jul 16, 2014

Start the registry editor (regedit). Set the HKEY_CLASSES_ROOT\Applications\python26.exe\shell\open\command key to: "C:\Python26\python26.exe" "%1" %*

Source of this solution: http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows/