Skip to content
Advertisement

VSCode Python: execute statement during debug

Is it possible to execute statements while the debug mode is active, possibly in the interactive mode?

Let’s say I’m working with a dataframe, and it doesn’t behave as I want. I go line by line in debug mode, and I want to check some properties while doing that, for example the number of NaN values.

Using the variable window to check the entries is obviously a waste of time for such a task.

I could use write a print statement into my code, stop the debugging, start the debugging again, and then the print statement is part of the code and will be executed.

But that would mean always stopping and starting debug, as soon as I run into an unforeseen problem and trying to find out what’s happening. Is it possible to execute statements while still remaining in debug, at the line you currently are at.

It would be especially good if there is a solution with running the statement in Interactive Mode because then I wouldn’t need to mess with the original program.

I hope it’s clear but if not, I can try to construct an example with screenshots. Any help would be appreciated!

Advertisement

Answer

When on a breakpoint you can use the debug console to run python code in the current context

It’s in the same tab as problems, output and terminal. typically under the editor pane

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement