Python Won’t Take Command Line Arguments – Windows Vista

by Lalit Kapoor on 2008-12-212008-12-21T15:29:56ZY-m-d">December 21, 20082008-12-21T15:29:56ZF j, Y

If you use python via the command line in Windows vista, you’ll notice that it won’t accept command line arguments if you run a script. For example this won’t work: python myscript.py argument1 argument2 Your python script won’t get the arguments. The fix for Windows Vista is:

  1. Get an application called: File Type Doctor
  2. Find the .py extension in the application
  3. Edit the Open action (add it if it doesn’t exist)
  4. Select the right python.exe file for "the application to carry out this action"
  5. put this in for the command line arguments (extactly as show, with the quotations): "%1" %*

  • The problem I had was that it doesn't pass the command line arguments if you don't have "python" at the front.

    So for example, this doesn't work for me:

    myscript.py argument1 argument2

    whereas this does:

    python myscript.py argument1 argument2

    I don't know if this is a related problem or not.
  • I had the same problem. After searching the entire registry I found the problem was with the following key:

    [HKEY_CURRENT_USER\Software\Classes\Applications\python.exe\shell\open\command]
    (default)="D:\Python26\python.exe" "%1"

    I changed it to:
    (default)="D:\Python26\python.exe" "%1" %*

    Python scripts now take arguments from the command line without 'python' at the beginning. That key was overriding the settings for Python.File.

    Very frustrating, eh? :P
  • Nice, good catch.
  • Chris Harris
    Thanks, that worked great.
blog comments powered by Disqus

Previous post:

Next post: