Hi @soumdtt
The easy, dirty and cumbersome way is to insert print()
statements (maybe in combination with if
statements) all over your code and try to catch bugs that way.
What I prefer to do is the easy and quick way to find bugs like that - is use %debug
magic command (link to docs):
Whenever you encounter an error, just open a new notebook cell, type %debug
and run the cell. This will open a command line where you can test your code like this:
This way you can access your code variables and more. The most used commands for the debugger:
for example:
would return:
or “p” and “print” are equivalent (see the table):
would return:
etc.
You can use these commands to check your variables. You can also add breakpoint()
in your code to “stop” the program for the debugger and find bugs or just get better understanding of your code that way.
When you’re done, don’t forget to exit (or quit) the debugger (because it halts the kernel):
After exiting the kernel is released and you can go on with your notebook:
Cheers