2

i have a file called "test.py" that imports argparse with the simple code:

import argparse
parser = argparse.ArgumentParser(description='Description')
parser.add_argument('-e','--event', help='event', required=True)
args = vars(parser.parse_args())
myArgument = args['event']

from windows if i call it with

python "test.py" -e hello

it works fine but if i try to call it directly with

test.py -e hello

it is calling python but i get an error "-e/--event is required" - i.e. it's not passing the arguments along.

my associations in windows are set up as:

assoc .py
.py=Python.File

ftype Python.File
Python.File = "C:\Python27,python.exe" "%1" %*

Can't seem to figure this out, because i have it working on another computer, so i'm guessing i have some path or environment variable not set up right?

Thanks in advance

Julian
  • 3,375
  • 16
  • 27
bruinlax
  • 229
  • 2
  • 5
  • Related: [Python script losing arguments when run from PATH on Windows](http://stackoverflow.com/q/10281595/95735), [How to execute Python scripts in Windows?](http://stackoverflow.com/q/1934675/95735) – Piotr Dobrogost Jul 28 '12 at 07:16

2 Answers2

2

I think there's an error in your file associations. I think this:

Python.File = "C:\Python27,python.exe" "%1" %*

should be:

Python.File = "C:\Python27\python.exe" "%1" %*

(change , to \)

...if this was just a typo here, then this question and answers may be of interest.

Basically, these associations aren't necessarily what is called when you run the program. (ie. I basically have the same associations as you, but if I run a python program like: "test.py -e hello", the progam test.py just opens up in my editor - it doesn't actually run the python program.)

You may want to look in both:

  • HKEY_CURRENT_USER\Software\Classes\.py, and
  • HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.py

for associations there.

Community
  • 1
  • 1
Gerrat
  • 28,863
  • 9
  • 73
  • 101
2

ftype shows what's in HKEY_LOCAL_MACHINE\Software\Classes but values in this registry branch could have been overwritten by values from HKEY_CURRENT_USER\Software\Classes. See what's the output of reg query HKCU\Software\Classes\Python.File\shell\open\command /ve. I guess your problem is caused by the lack of %* fragment in this registry entry.

Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366