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" %*

{ 4 comments… read them below or add one }

1 Chris Harris May 7, 20092009-05-07T04:52:51ZF j, Y at 12:52 am2009-05-07T04:52:51Zg:i a

Thanks, that worked great.

Reply

2 Bryce Thomas November 5, 20092009-11-05T06:38:45ZF j, Y at 2:38 am2009-11-05T06:38:45Zg:i a

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.

Reply

3 John Hatch December 17, 20092009-12-17T22:41:00ZF j, Y at 6:41 pm2009-12-17T22:41:00Zg:i a

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

Reply

4 Lalit Kapoor December 18, 20092009-12-18T04:38:08ZF j, Y at 12:38 am2009-12-18T04:38:08Zg:i a

Nice, good catch.

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: