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

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.