1

In windows 7, if a python (2.7.10) script has been associated with the Python interpreter and the extension has been registered in the PATHEXT (windows) list, then when you kick off a script, one can simply type:

MyPythonScript

instead of the traditional:

python MyPythonScript.py 

Which is great - but it no longer (appears) to take command line arguments. For example, consider the two below examples of a script that takes command line arguments. First the traditional way:

>>>> python echo_input.py --help

usage: echo_input.py [-h] [-s SIMPLE_VALUE] [-c] [-t] [-f] [-a COLLECTION]
                     [-A] [-B] [--version]

optional arguments:
  -h, --help       show this help message and exit
  -s SIMPLE_VALUE  Store a simple value
  -c               Store a constant value
  -t               Set a switch to true
  -f               Set a switch to false
  -a COLLECTION    Add repeated values to a list
  -A               Add different values to list
  -B               Add different values to list
  --version        show program's version number and exit

works just fine, but if it is invoked the alternative way:

echo_input --help

simple_value     = None
constant_value   = None
boolean_switch   = False
collection       = []
const_collection = []

It appears to no longer recognizes the command line arguments. FYI: The above script (by default) prints out those 5 lines if the it is run w/out any parameters as shown below for contrast:

>python echo_input.py

simple_value     = None
constant_value   = None
boolean_switch   = False
collection       = []
const_collection = []

So it appears as though it has lost it's ability to take command line arguments such as a simple flag for help.

I'm stuck for both an answer to this and a work around and would greatly appreciate any suggestions or experience.

Thank you in advance for your time ... :-)

Sources of inspiration:

Registering Python Scripts to run on Windows:

Python FAQ2:

1
  • It's not an argparse issue. It's a question of what is in sys.argv. Commented Jan 17, 2016 at 2:05

1 Answer 1

2

Does this work (thanks @eryksun for suggested fixes -- I don't have a Windows machine any more)?

C:\>ftype Python.File="C:\Python27\python.exe" "%1" %*
C:\>assoc .py=Python.File

This adds/modifies the ProgId in HKLM\SOFTWARE\Classes. Depending on the current configuration, you may also have to select this ProgId (Python.File) in Explorer's "open with" dialog.

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

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.