![]() ![]() ![]() Once inside make_dot_string you can examine its local variables and step through its code specifically.Ĭontinue stepping with Step Into and notice that when you reach the end of the make_dot_string, the next step returns to the for loop with the new return value in the s variable. Step Into means that the debugger enters inside any function call for which it has debugging information, such as make_dot_string. Press Enter or select any area outside that value to apply any changes.Ĭontinue stepping through the code using Step Into. In the Locals or Autos window, double-click in the Value column for either the i or s variables to edit the value. The debugger doesn't stop inside that function unless a separate breakpoint exists there.Ĭontinue stepping over the code a few more times and observe how the values in the Locals or Autos window change. Step Over here specifically means that the debugger runs the whole of make_dot_string and pauses when it returns. Step over the next line of code, which calls make_dot_string and pauses. Notice in the code, how the variable i is now defined in the Locals and Autos windows. Stepping means that the debugger runs the current line of code, including any function calls, and then immediately pauses again. Step over the for statement using Step Over. Runs the remainder of the current function and pauses in the calling code. Runs the next line of code without entering into called functions. Runs the next line of code, entering into called functions. This is helpful when you navigate around within your code during a debugging session and want to quickly return to the point where the debugger is paused. Switches to the next line of code to run. Stops the program wherever it is, and restarts it from the beginning in the debugger. Stops the program wherever it is, and exits the debugger. Runs the program until the next breakpoint or until program completion. The buttons from left to right as follows: Button This toolbar provides quick access to the most common debugging commands (which can also be found on the Debug menu): Observe the debugging toolbar (shown below) along the top of the Visual Studio window. Variables that are in-scope appear in the Autos window when they're defined you can also switch to the Locals view at the bottom of that window to show all variables that Visual Studio finds in the current scope (including functions), even before they're defined: Here you can inspect the call stack and examine variables. ![]() Start the debugger again ( F5) and see that running the code stops on the line with that breakpoint. A red dot appears in the gray margin to indicate the breakpoint (as noted by the arrow below): Set a breakpoint on the for statement by clicking once in the gray margin by that line, or by placing the caret in that line and using the Debug > Toggle Breakpoint command ( F9). To close the output window automatically when the program completes, select the Tools > Options menu command, expand the Python node, select Debugging, and then clear the option Wait for input when process exits normally:įor more information about debugging and how to set script and interpreter arguments, see Debug your Python code. Press any key to close the output window. As of yet, nothing has been done to pause the program while it's running, it will just print a wave pattern for a few iterations. This command runs the code in the debugger. St = ' ' * numspaces + 'o' # place 'o' after the spacesĬheck that the code works properly by pressing F5 or selecting the Debug > Start Debugging menu command. Numspaces = int(20 * cos(rad) + 20) # scale to 0-40 spaces Rad = radians(x) # cos works with radians # Create a string with spaces proportional to a cosine of x in degrees It also places the for loop into a main function and runs it explicitly by calling that function: from math import cos, radians This variation of the code expands make_dot_string so that you can examine its discrete steps in the debugger. Replace the code in the PythonApplication1.py file with the following code. Such actions are essential for tracking down program bugs, and also provide helpful aids for following the exact program flow. At any point when the program is paused in the debugger, you can examine the entire program state and change the value of variables. You can also pause the program whenever certain conditions are true. In the debugger, you can run your code step by step, including every iteration of a loop. Visual Studio provides capabilities to manage projects, a rich editing experience, the Interactive window, and full-featured debugging for Python code. Previous step: Use the Interactive REPL window Applies to: Visual Studio Visual Studio for Mac Visual Studio Code ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |