VScode、argparse库、lauch.json中args参数

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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值