2

filename:test.py

import sys
print(sys.version)
print(sys.argv)

I typed python test.py 1 2 3 in the cmd console , it works well.

3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)]
['test.py', '1', '2', '3']

However , I type test.py 1 2 3 in the cmd console, it can only get the first argument.

3.5.0b4 (v3.5.0b4:c0d641054635, Jul 26 2015, 06:55:14) [MSC v.1900 32 bit (Intel)]
['E:\\Bin\\iproc\\test.py']

How can I get these arguments ?

4
  • 1
    Hm, can't seem to reproduce this. Can you confirm that E:\Bin\iproc\test.py is the right copy of test.py? Is the cmd window finding one in your PATH to run instead? The version of PYthon appears to be different, too, which hints it might a different copy. Commented Mar 11, 2016 at 8:36
  • python test.py 1 2 3 and import sys print(sys.argv) that's ok tutorialspoint.com/python/python_command_line_arguments.htm Commented Mar 11, 2016 at 8:37
  • I am sure there is only one copy of test.py in my PATH as I run where test.py,only one test.py is the result. Commented Mar 11, 2016 at 8:50
  • I test this file in my debian os , it is ok . Commented Mar 11, 2016 at 9:02

2 Answers 2

2

Sounds like your Windows file association is bad. Make sure arguments are passed as %%*. Use the assoc and ftype commands in cmd.exe to check. For example:

ASSOC .py=Python.File
FTYPE Python.File="C:\Python35\python.exe" "%%1" %%*
Sign up to request clarification or add additional context in comments.

2 Comments

It does not work.c:\bin\python35\python.exe: can't open file '%1': [Errno 2] No such file or directory
What didn't work? Did you get that error from the ftype command or when you tried to run the python script? What does ftype show?
1

Yes, my Windows file association is bad.I Checked the registry , and finally changed the registry . The problem is solved .

[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command] @="\"c:\\bin\\python35\\python.exe\" \"%L\" %*"

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.