你可以在 VS Code 中调试 Python 程序时,如何运行单行或选定的代码?

huangapple go评论98阅读模式
英文:

How can I run a single line/selection when debugging Python programs in VS Code?

问题

在VS Code的调试控制台中如何运行单行代码?在调试过程中,经常会遇到我想要运行单行代码以覆盖变量的情况。在spyder中可以轻松实现这一点(我正在迁移),但我找不到在VS Code中快速执行的方法。唯一的方法似乎是在调试控制台中每次进行复制和粘贴,但我正在寻找一种更快的方法。

我正在使用Python,没有截图要附上。我只是简单地询问是否有一种在调试过程中快速运行特定行的方法。在spyder中,可以通过“运行所选内容或当前行”命令轻松实现这一点。我在Visual Studio Code中寻找类似的功能。

英文:

How can I run a single line in debug console in VS Code? It often happens that during debugging I want to run single lines to override variables. That can be done smoothly with spyder (which I'm migrating from), but I can't find a way to do it quickly in VS Code. The only way seems doing copy and paste every time in the debug console, but I'm looking for a quicker way.

I'm using Python and there's no screenshot to attach. I'm simply asking whether there's a quick way to run specific lines during debugging. In spyder this can be achieved pretty easily by the Run selection or current line command. I'm looking for the equivalent in Visual Studio Code.

答案1

得分: 1

尝试将 "console": "internalConsole" 放入您的 launch.json 中。这将使其使用集成控制台,我认为您可以在那里找到您要查找的内容。我不清楚如何运行代码的选择部分,但我刚刚尝试了一下,我可以在集成控制台的输入框中写入要在断点处暂停时由 Python 解释器执行的内容。

英文:

Try to put "console": "internalConsole" in your launch.json. That will make it use the integrated console, where I think you can get what you are looking for. I don't know about running selections of code, but I just tried, and I could write things for the Python interpreter to execute when paused at breakpoints in the integrated console's input box.

huangapple
  • 本文由 发表于 2023年6月26日 19:15:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556158.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定