![how to use pycharm for debugging how to use pycharm for debugging](https://www.jetbrains.com/pycharm/features/screenshots/debugger/VisualDebuggingOverview.png)
You have a couple of choices for how to run the P圜harm debugging tool. Here are a few brief notes on how to use the debugging tool in P圜harm. The minute something happens that you didn’t expect, figure out precisely what occurred. Watch variable values closely, and watch where the program counter moves to.
#HOW TO USE PYCHARM FOR DEBUGGING CODE#
Use the debugging tool in P圜harm or some other code editor to step through the code.
![how to use pycharm for debugging how to use pycharm for debugging](https://kedro.readthedocs.io/en/latest/_images/pycharm_add_py_run_config.png)
You might then insert additional print-statements to get a better idea of how the code behaves, and you might remove some of the print-statements that you previously inserted in order to reduce clutter in the console. As you scan the console output, you’ll see what your program is actually doing. Insert print-statements into your code to tell you the order in which functions and statements execute and the values of variables. Be absolutely certain about the type of the value that you intend to be stored in each variable, and make sure that this is the type actually stored. Start at the first executable line and work your way through, writing down the values of variables as you go. Based on what you expected to happen and what actually happened, come up with a few possible places where the earliest problem could have occurred. So you want to find the first place where something went haywire. Bugs often have a cascading effect: once one bug happens, strange behavior can follow. “Aha! Perhaps I swapped the x- and y-coordinates somewhere.”įind the earliest point in the code where something unexpected happens. Not, “the circle is in the wrong place,” but “I expected a circle to be drawn at the location 200, 100, but it seems to have been drawn at 100, 200.” By asking the question precisely, you can sometimes solve the problem immediately. What actually happened? What’s the difference between what you expected and what you got? Be as precise as possible. Why? Debugging is as much an art as a science, but here is a procedure that can help.Īsk yourself what you expected.
![how to use pycharm for debugging how to use pycharm for debugging](https://resources.jetbrains.com/help/img/idea/2021.2/py_path_mapping_in_debug_server.png)
Catching and fixing bugs requires you to act like a detective: something that should have been a normal situation has gone wrong. We often observe a bug for the first time when we run the program and notice unexpected behavior.