Python 调试技巧

使用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
进入调试模式后,可以在终端修改、打印、显示变量。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值