I have a Python Tool, which I call which I call with some (use case depended) arguments and which is still under development.

In my launch.json I have:

{
    "name" : "Project-ID XXX: Some name",
    "type" : "debugpy",
    "program" : "path_to_my/python_tool.py",
    "args" : [
        "--some-property", "argument",
        "--another-property", "lalala",
        "--this-list-goes", "On and On and On..."
    ],
    "env": {
        "PYTHONOPTIMIZE": "0"
    }
}

If I’m done developing and want to run the full program I change PYTHONOPTIMIZE to 1 and run it with CRTL+F5.

Can I somehow tell vscode to use PYTHONOPTIMIZE=0 when debugging (F5) and PYTHONOPTIMIZE=1 when running (CRTL+F5) the program?

I’ve looked through the documentation of vscode and didn’t find anything suiting.

Is there maybe another common way to solve my problem? After all the -O, or PYTHONOPTIMIZE option sets the internal __debug__ variable to False when given, so I belive there must be som vscode way to set it within the launch.json.

New contributor

Grzegorz Lippe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.