使用vs code像Matlab一样调试Python
在VS code中可以设置断点,之后像调试Matlab程序一样调试:在界面最下方能找到一个DEBUG CONSOLE的终端,可以在这个终端里对变量进行操作,包括改变变量,如果打印、显示变量,就像Matlab一样。
VS code调试添加命令行参数
在Debug菜单中找到 Open Configuration 可以打开配置项。如果没有配置项,就点 Add Configuration 新增一个配置项。
打开配置项后,找到 args 的那一项。如果没有就新增一行:
"args": ["param 1", "param 2"]
注意:
- 所有参数都要用引号包起来,
- 如果有多个参数要用逗号隔开
参考:https://blog.csdn.net/u012332816/article/details/80801106
在出错时停止进入Debug模式
python -m pdb -c continue myscript.py
If you don't provide the -c continue flag then you'll need to enter 'c' (for Continue) when execution begins. Then it will run to the error point and give you control there. As mentioned by eqzx, this flag is a new addition in python 3.2 so entering 'c' is required for earlier Python versions (see https://docs.python.org/3/library/pdb.html).
参考:https://stackoverflow.com/questions/242485/starting-python-debugger-automatically-on-error
进入调试模式后,可以在终端修改、打印、显示变量。