DEV Community

Cover image for Debugging (Also) The Standard Library In Python

Debugging (Also) The Standard Library In Python

Mohammad Aziz
I write bugs 🐛
・2 min read

We all have to debug our application very often in order to fix a bug, learn something new, or to understand the flow of our code, etc.

Have you ever tried to debug your code in Python and more specifically in VS Code?

If you have then you will find that the VS Code is not letting you get into the standard library packages. I wanted to know what is happening under the hood of those files so get a better understanding of why my code is not working as expected.

I was trying to create_connection with the socket library. Every time when my file ran I was getting this error.

Not quite helpful for me. I wanted to put my breakpoint to where it was throwing the error. Now the question was how to do this?

There are two steps for it:

  1. Add a configuration file if you don't have any.
  2. Add justMyCode to false. 🎉

1. Add the configuration file

It is very simple to do.

  • Just go to the Debug tab
  • Click on the No Configurations option
  • Select Add Configuration...

After that just to select any one of the prompted options, Python File was in my case but VS Code also supports frameworks like Django, Flask, and Pyramid etc.

Once this has been done you will see and .vscode folder and in that folder, there will be a file named launch.json.

2. Adding Magical Words 😄

Now the time comes to add those magical words which will make you able to debug the files other than you code.

In launch.json, select the one configuration and add justMyCode: false. THAT'S IT!

The VS Code will now allow you to roam around the code of the standard library and you can find the exact reason why your code is not working as expected.

In my case, the problem was that you don't prepend https:// when you are passing host and port to socket.create_connection.


Follow me on Twitter

Cover Image: Chris Ried on Unplash

Discussion (0)