在 VS Code 中,可以按照以下步骤设置按请求触发 Python 调试器:
import pdb; pdb.set_trace()
来设置断点。Ctrl + Shift + D
来打开调试面板。launch.json
配置文件。launch.json
文件中,找到 "configurations"
字段,并在其下方添加以下配置:{
"name": "Python Debug",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
launch.json
文件,并返回调试面板。注意:在调试时,确保你的 Python 程序在调试器中运行,而不是在终端或其他地方运行。
希望以上解决方案能对你有所帮助!