今天在使用visual studio code对python进行调试时,发现一个非常人性化的功能,只要配置合适,可以以任何你想要的方式进行调试,不仅可以带参数,而且还可以方便的选择要调试的文件。
首先点击工具栏里的调试按钮,然后点击里面的“打开配置”按钮,点击以后会弹出“launch.json”配置文件。



在图中,“args”表示添加的关键词,“-c"和“conf/train.cfg”是笔者调试的时候使用的两个参数,经过上诉的简单配置就可以实现python的带参调试了。此外在下图中介绍配置文件中的几个常用的关键字。
${file} the current opened file(当前打开的文件)
${cwd} the task runner's current working directory on startup(),表示当前的工作空间

整个配置表示,笔者要对工作空间下tools子目录下的train.py文件进行调试,其中,-c conf/train.cfg为起调试参数,有点类似于python -m pdb (workspace_root)/tools/train.py -c conf/train.cfg命令,但是在visual studio code中,当配置完launch.json之后,按F5就可以进行可视化的调试了。
转载请注明出处。
网友评论