我如何使用 MS Visual Studio 2015 中的命令行参数 运行 python 脚本
How do I run python script with command line arguments from MS Visual Studio 2015
我想 运行 命令行选项的解析器,取自官方 Python 2.7 文档 https://docs.python.org/2/library/argparse.html#module-argparse 使用 MS Visual Studion 2015 (Python工具)。我创建了名为 prog.py
.
的脚本
#file_name='prog.py'
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+',
help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',
const=sum, default=max,
help='sum the integers (default: find the max)')
args = parser.parse_args()
print args.accumulate(args.integers)
我通常 运行 我的脚本选择几行代码并按 Ctrl+E,E。但是这次我需要 运行 整个脚本加上额外的命令行参数。在这种特殊情况下,我想执行命令:
python prog.py -h
从我的脚本中查看帮助。并且:
python prog.py 1 2 3 4
python prog.py 1 2 3 4 --sum
看看它是如何工作的。
结果必须在 Python 2.7 Interactive window 环境中可见。
他们如何在 MS Visual Studio 2015 中做到这一点?
您可以右键单击包含您的脚本的 VS 项目并转到“属性”。然后在“调试”选项卡下,您可以添加 "Script Arguments",当您点击“开始”(F5) 时,它会被传入。
我想 运行 命令行选项的解析器,取自官方 Python 2.7 文档 https://docs.python.org/2/library/argparse.html#module-argparse 使用 MS Visual Studion 2015 (Python工具)。我创建了名为 prog.py
.
#file_name='prog.py'
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+',
help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',
const=sum, default=max,
help='sum the integers (default: find the max)')
args = parser.parse_args()
print args.accumulate(args.integers)
我通常 运行 我的脚本选择几行代码并按 Ctrl+E,E。但是这次我需要 运行 整个脚本加上额外的命令行参数。在这种特殊情况下,我想执行命令:
python prog.py -h
从我的脚本中查看帮助。并且:
python prog.py 1 2 3 4
python prog.py 1 2 3 4 --sum
看看它是如何工作的。 结果必须在 Python 2.7 Interactive window 环境中可见。 他们如何在 MS Visual Studio 2015 中做到这一点?
您可以右键单击包含您的脚本的 VS 项目并转到“属性”。然后在“调试”选项卡下,您可以添加 "Script Arguments",当您点击“开始”(F5) 时,它会被传入。