Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22908

Everyday Superpowers: TIL Debug any python file in VS Code

$
0
0

One of my frustrations with VisualStudio Code was creating a `launch.json` file whenever I wanted to debug a one-off Python file.

Today, I learned that you could add a debugger configuration to your user settings. This allows you always to have a debugging configuration available.

How to do this

Create a debugging (or launch) configuration:

  1. Select the "Run and Debug" tab and click "create a launch.json file"

A screen capture that shows a VisualStudio Code window with  the

2. Choose "Python File"

3. VS Code will generate a configuration for you. This is the one I used, where I changed the `"justMyCode"` to `false`, so I can step in to any Python code.

{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "justMyCode": false
}

4. Copy the config (including the curly braces)

5. Open your user configuration (`⌘`/`Ctrl` + `,`) and search for "launch".

6. Click "Edit in settings.json"

7. Add your configuration to the `"configurations"` list.

This is what mine looks like, for reference:

...
"launch": {
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ],
    "compounds": []
}

Read more...

Viewing all articles
Browse latest Browse all 22908

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>