Appendix B. Advanced VS Code Functionality
This appendix shows you how the debugger works in VS Code and how you can run Jupyter notebooks directly from within VS Code. The topics are independent of each other, so you may read them in any order.
If you’ve ever used the VBA debugger in Excel, I have good news for you: debugging with VS Code is a very similar experience. Let’s start by opening the file debugging.py from the companion repository in VS Code. Click into the margin to the left of line number 4 so that a red dot appears—this is your breakpoint where code execution will be paused. Now hit F5 to start debugging: the Command Panel will appear with a selection of debug configurations. Choose “Python File” to debug the active file and run the code until it hits the breakpoint. The line will be highlighted and code execution pauses, see Figure B-1. While you debug, the status bar turns orange.
If the Variables section doesn’t show up automatically on the left, make sure to click on the Run menu to see the values of the variables. Alternatively, you can also hover over a variable in the source code and get a tooltip with its value. At the top, you will see the Debug Toolbar that gives you access to the following buttons from left to right): Continue, Step Over, Step Into, Step Out, Restart, and Stop. When you hover over them, you will also see the keyboard shortcuts.
Let’s see what each of these buttons ...