I'm working with my Django app. For some reason an element of a list is being assigned incorrectly.
I'm trying to set a break where I think the error is occurring. ( line 20 )
I'm invoking pdb with this line of code:
import pdb; pdb.set_trace()
However, inside the code, I can't seem to set a Break.
(Pdb) b 20
*** Blank or comment
(Pdb) break 20
*** Blank or comment `
What am I doing wrong?
Optionally, you can also tell pdb to break only when a certain condition is true. Use the command b (break) to set a breakpoint. You can specify a line number or a function name where execution is stopped. If filename: is not specified before the line number lineno , then the current source file is used.
To remove all commands from a breakpoint, type commands and follow it immediately with end ; that is, give no commands. Specifying any command resuming execution (currently continue , step , next , return , jump , skip , and quit ) terminates the command list as if that command was immediately followed by end .
The module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame.
Once you get you pdb prompt . Just hit n (next) 10 times to exit the loop.
pdb is telling you that line 20 of the file you're in doesn't contain code; it's either blank or just contains a comment. Such a line will never actually be executed, so a breakpoint can't be set on it.
Use the 'list' command to see the code of the file you're currently in ('help list' for details on this command), and then set breakpoints on lines which include executable code.
You can also use the 'where' command to see the stack frame, since you might not be in the right file because you're not looking at the level of the stack frame where you think you are. Use 'up' and 'down' to go to the level of the stack where you want to debug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With