当前位置:   article > 正文

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

launch.json args 参数

argparse库是用于接受从command-lines传来参数的库,即argparse库接受命令台终端中传入的参数,但在VScode中并不需要从command-lines来配置参数。VScode通过launch.json文件配置args参数,并通过
在python文件中引入sys模块调用参数

args1=sys.argv[3]
  • 1

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"
            ]
        }
    ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

上面的代码表面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
  • 1

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/770924
推荐阅读
相关标签
  

闽ICP备14008679号