Coming off as a noob here, but how do you actually utilize the debugger.
Mostly working on python stuff in VS Code, sometimes I just run the code and look at the error. Sometimes I try the debug and run option but it acts the same as just running the code; there’s some stuff like variables window but I don’t know how to utilize the information to debug.
Debuggers allow you to step through code and inspect the program state at any moment during execution. You can even sometimes run commands inline to see how stuff reacts.
This means you can usually just hover a variable or something in your IDE while execution is paused and see its current value without having to restart execution every time you want to print something different.
You can even sometimes run commands inline to see how stuff reacts.
It’s honestly not a bad way to write some of the more complex lines of code too. In python/vscode(ium), you can set a breakpoint where you’re writing your code and then write the next line in the watches section. That way you can essentially see a live version of the result you’re getting. I especially like this for stuff like list comprehension, or indexing logic where you might normally expect a possible off by one or key error.
I don’t know how to use vscode. In general in Python you can do breakpoint() and your code will pause there and become interactive. If you’re running in docker you’ll want to attach to the container. When it hits the breakpoint you basically drop into a normal python repl with extra features.
This is really, really, good for debugging and developing. You can interactively examine stuff and try stuff right there. You don’t have to rerun the whole thing to be like “ok what’s the second item in the list? Is this syntax right to sort it?” or whatever you’re trying to do
I use pdb++ for syntax highlighting and some other qol features, too.
Coming off as a noob here, but how do you actually utilize the debugger.
Mostly working on python stuff in VS Code, sometimes I just run the code and look at the error. Sometimes I try the debug and run option but it acts the same as just running the code; there’s some stuff like variables window but I don’t know how to utilize the information to debug.
Debuggers allow you to step through code and inspect the program state at any moment during execution. You can even sometimes run commands inline to see how stuff reacts.
This means you can usually just hover a variable or something in your IDE while execution is paused and see its current value without having to restart execution every time you want to print something different.
It’s honestly not a bad way to write some of the more complex lines of code too. In python/vscode(ium), you can set a breakpoint where you’re writing your code and then write the next line in the watches section. That way you can essentially see a live version of the result you’re getting. I especially like this for stuff like list comprehension, or indexing logic where you might normally expect a possible off by one or key error.
I don’t know how to use vscode. In general in Python you can do
breakpoint()
and your code will pause there and become interactive. If you’re running in docker you’ll want to attach to the container. When it hits the breakpoint you basically drop into a normal python repl with extra features.https://docs.python.org/3/library/pdb.html
This is really, really, good for debugging and developing. You can interactively examine stuff and try stuff right there. You don’t have to rerun the whole thing to be like “ok what’s the second item in the list? Is this syntax right to sort it?” or whatever you’re trying to do
I use pdb++ for syntax highlighting and some other qol features, too.
Ostensibly I debug Python in VSCode by installing the correct plugins and adding appropriate run configs to the debugger launch configuration.
But honestly I debug most of it with
import pdb; pdb.set_trace()
…