[Visual Studio Code] [Python] Tasks.json + problemMatcher settings for Python

Purpose

I wanted to see the Python Traceback error

Current problems (2017/02/27)

environment

Sample to be analyzed

def main():
    raise Exception("Exception message")

if __name__ == '__main__':
    main()
Traceback (most recent call last):
  File "c:\path\to\test.py", line 5, in <module>
    main()
  File "c:\path\to\test.py", line 2, in main
    raise Exception("Exception message")
Exception: Exception message

Setting Example

Tasks for python.json(The extension is JSON, but you can write comments)


{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "python",
    "isShellCommand": true,
    "args": [
        "${file}"
    ],
    "showOutput": "always",
    "problemMatcher": {
        "owner": "python",
        "fileLocation": "absolute",
        "pattern": //[
            {
                "regexp": "^.*File \"(.*)\", line (\\d+?), in.*$",
                "file": 1,
                "line": 2
                //"loop": true
            }
            //I really want to get the error message on the last line
            //now"problemMatcher"Cannot be handled with the syntax of
            // https://code.visualstudio.com/Docs/editor/tasks#_defining-a-multiline-problem-matcher
            // https://github.com/Microsoft/vscode/blob/master/src/vs/platform/markers/common/problemMatcher.ts
            //{
            //    "regexp": "^(.*):(.*)$",
            //    "severity": 1,
            //    "message": 2
            //},
        //]
    }
}

The output example is as follows.

1.png

Supplement

If you want to stop at the point where the exception was thrown at runtime, you can solve it by just checking "All Exceptions" at the breakpoint at the bottom left of the debug screen. (However, there is one more step because you have to press F5 twice)

1.png

reference

Recommended Posts

[Visual Studio Code] [Python] Tasks.json + problemMatcher settings for Python
Settings for Python coding in Visual Studio Code
Make Visual Studio Code autocomplete for python external libraries
Enable the virtualenv Python virtual environment for Visual Studio Code
Installation of Visual studio code and installation of python
Python Tools for Visual Studio Installation Guide
Build Python development environment with Visual Studio Code
Django with Python Tools 2.2 for Visual Studio (PTVS 2.2)
I customized it with Visual Studio Code (mainly for python), so I will summarize it
VS Code settings for developing in Python with completion
Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment with Windows + Python + PipEnv + Visual Studio Code
AWS SDK for Python (Boto3) development in Visual Studio 2017
Python code memo for yourself
[Python] Sample code for Python grammar
Python development in Visual Studio
Set up a Python development environment with Visual Studio Code
Do something like a Python interpreter in Visual Studio Code
Install python and Visual Studio Code on windows10 (April 2020 version)
Build Python3 for Windows 10 on ARM with Visual Studio 2019 (x86) on Windows 10 on ARM
[Visual Studio Code] [Python] [Windows] Support for garbled Japanese characters in Python in VS Code task / debug output
Java with Visual Studio Code (Part 2)
Snippet settings for python jupyter notebook
Visual Studio Code may be good
Emacs settings for Python development environment
Try to create a python environment with Visual Studio Code & WSL
Bash, Python, Javascript, code command, etc. in Visual Studio Code on Mac
About the procedure for linking Visual Studio Code for Windows and WSL
A memo for those who use Python in Visual Studio (me)
Use Jupyter Notebook with Visual Studio Code on Windows 10 + Python + Poetry + pyenv-win
Creating amateur python environment settings (for MAC)
Build an environment to execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people)
python> coding guide> PEP 0008 --Style Guide for Python Code
From re-environment construction of Python to graph drawing (on visual studio code)
R code compatible sheet for Python users
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Steps to put dlib in Python Tools for Visual Studio and have fun
A note I was addicted to when running Python with Visual Studio Code
Settings for uploading Python packages locally to PyPI
Run Python YOLOv3 in C ++ on Visual Studio 2017
Time when terminal disappears in Visual Studio Code
Logging settings for daily log rotation in python
[Python / Chrome] Basic settings and operations for scraping
Code for checking the operation of Python Matplotlib
Settings for getting started with MongoDB in python
2016-10-30 else for Python3> for:
python [for myself]
python environment settings
VS Code settings
python character code
Initial settings for using Python3.8 and pip on CentOS8
Translator in Python from Visual Studio 2017 (Microsoft Translator Text API)
Preparing to use Tensorflow (Anaconda) with Visual Studio Code
Specific sample code for working with SQLite3 in Python
App development to tweet in Python from Visual Studio 2017
Try debugging Python on Raspberry Pi with Visual Studio.
Tips for speeding up python code correctly with numba
Until you run server Django in Visual Studio Code
Japanese output when dealing with python in visual studio
Settings for testing C ++ 11 Python modules on Travis CI
Expose settings.json for efficient Python coding in VS Code