赞
踩
argparse库是用于接受从command-lines传来参数的库,即argparse库接受命令台终端中传入的参数,但在VScode中并不需要从command-lines来配置参数。VScode通过launch.json文件配置args参数,并通过
在python文件中引入sys模块调用参数
args1=sys.argv[3]
launch.json文件:
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Launch Python Program", "type": "python", "request": "launch", "program": "${workspaceRoot}\\associate.py", "console": "integratedTerminal", "args": [ "first_file","${workspaceRoot}/rgb.txt", "second_file","${workspaceRoot}/depth.txt", "--first_only","True", "--offset","0.0", "--max_difference","0.02" ] } ] }
Python文件:
import argparse
import sys
parser = argparse.ArgumentParser(description='命令行中传入一个数字')
#type是要传入的参数的数据类型 help是该参数的提示信息
parser.add_argument('first_file', help='first text file (format: timestamp data)',default='G:\\Code_Repository_lichenwgei\\rgbd_dataset_freiburg1_xyz\\rgb.txt')
parser.add_argument('second_file', help='second text file (format: timestamp data)',default='G:\\Code_Repository_lichenwgei\\rgbd_dataset_freiburg1_xyz\\depth.txt')
print(sys.argv[3])
args = parser.parse_args()
上面的代码表面sys.argv[3]可正常调用args参数,但是args = parser.parse_args()运行时就会保存,说明argparse库不接受launch.json文件传入的参数
https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
介绍了launch.json文件配置
argparse库使用要从控制台直接输入参数
python2 associate.py ./rgb.txt ./depth.txt > assoaication.txt
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。