Stepping functionalities

Stepping functionalities are a way to control how the execution of your program should proceed. Going from left to right in the toolbar, we have the following functionalities:

  • Show execution point/Show the current program execution point : This will move the caret in the editor to the line where the execution is currently at, as well as jump to the corresponding frame in the Debug panel.
  • Step over/Step to the next line in this file : This will move the execution to the next line of code in the current scope (function or the main scope). If it is the last line of a function, the execution will return to the parent scope that called the current function.
  • Step into/Step to the next line executed : This will move the execution into any method that's called at the current line of code. This feature is useful when we'd like to inspect external APIs, and we will come back to it after this list.
  • Step into my code/Step to the next line executed ignoring libraries : This is somewhat the opposite of the previous functionality. This will move the execution to the next line of your own code.
  • Force step into/Step into, ignore stepping filters for libraries, constructors, and so on : This will allow the execution to step into any external method that's being used in the current line of code, even if the method was previously ignored. This button is appropriately disabled if you haven't ignored an API yet (which is the case in our example).
  • Step out/Step to the first line that's executed after returning from this method : This will have the execution step out of the current function or method and return to the parent scope.

Let's look at some of these functionalities in action:

  1. With the execution of our example program currently at line 3 (where the built-in input() function is used), click on the step into  button, and you will see that the parse.py file, which implements the input() function, is opened in the editor, and the execution moves to the first line of the quote() method in that file.

    Again, this functionality is quite useful when you'd like to inspect built-in or external APIs that you are not familiar with.
  2. Now, click on the step out  button, and the execution will return to our own code. Here, the console is waiting for our input, so simply enter a number and move forward with our debugging session. Note that after entering your input, other built-in files might be opened in the editor by PyCharm. This is because the step into button is still active. Simply use the step out button until you get back to our example file, which should now look similar to the following:
Inline debugging inside a function
  1. Let's focus on the current inline debugging output inside our change_middle() function: at line 1, we can see the value of the my_list parameter that's been passed to the function, which is the list [0, 1, 2]; at line 3, we can see the value of the x variable that's been entered by the user from the console.
    Again, this inline debugging feature is significantly helpful, especially in large functions and programs where there are many values for the debugging programmer to keep track of.
  2. We have discussed the most common stepping functionalities in support for debugging purposes in PyCharm. For now, simply step through the rest of the example program using either the resume button or the step over button.

In the rest of this section, we will look into more advanced features when it comes to keeping track of variables.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.122.4