[英]How can I get command line arguments(sys.argv) in python
filename:test.py 文件名: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. 我在cmd控制台中键入python test.py 1 2 3
,它很好用。
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. 但是,我在cmd控制台中键入test.py 1 2 3
,它只能获取第一个参数。
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 ? 我如何获得这些论点?
Sounds like your Windows file association is bad. 听起来您的Windows文件关联错误。 Make sure arguments are passed as %%*
. 确保将参数作为%%*
传递。 Use the assoc
and ftype
commands in cmd.exe
to check. 在cmd.exe
使用assoc
和ftype
命令进行检查。 For example: 例如:
ASSOC .py=Python.File
FTYPE Python.File="C:\Python35\python.exe" "%%1" %%*
Yes, my Windows file association is bad.I Checked the registry , and finally changed the registry . 是的,我的Windows文件关联错误。我检查了注册表,最后更改了注册表。 The problem is solved . 问题已经解决了 。
[HKEY_CLASSES_ROOT\\Applications\\python.exe\\shell\\open\\command] @="\\"c:\\\\bin\\\\python35\\\\python.exe\\" \\"%L\\" %*"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.