赞
踩
想在vsCode中调试带参数的python程序,参数设置方式。
Run->open Configurations,打开lanuch.json。在lanuch.json中添加代码后效果如下:
"version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "args":[ "train", "--cfg","cfg/yolo_hand/yolo_hand.cfg", "--data","cfg/yolo_hand/Test.data", "--weights","cfg/yolo_hand/yolo_hand_best.weights", "--batch-size","64", "-sr", "--s","0.001", "--prune","0" ] } ]
args列表里是我们的参数和值。
备注:store_true就代表着一旦指令里写了这个参数,那么将其值设为True,没有时,默认状态下其值为False。同理:store_false代表一旦命令中有此参数,其值则变为False,默认为True。
代码中的“-sr”就是设置了action=‘store_true’,所以没有设置值。
若程序代码中有“cmd”参数,如:
parser.add_argument('cmd', type=str, choices=['train', 'test'], help='train or test')
则launch.json中只需写入一个“choices”的字符串,如上所示。
值为int型或者其他,也都需要加双引号。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。