Inspired by my current area of work - which involved Python.
This is what I do for Flask.

MS Link
https://code.visualstudio.com/docs/python/debugging
For any regular Python debugging

Evidence
import os
for key in os.environ.keys():
print(f"{key}={os.environ.get(key)}")
After doing a F5 in VS Code with a file containing the above snippet:

Update on Feb 18
After receiving a comment I think the OP wants to run a script before debugging the Fask application. The steps that worked for me are below.
Overview
I ended up with the following files:
- Add a PowerShell file
dosomething.ps1
(my custom script which I intend to launch before every debug session)
- Add a
task.json
(launch dosomething.ps1)
- Edit the existing
launch.json
by linking it with the task in task.json

The file dosomething.ps1
Write-Host "Inside do something"
Write-Host "The value of the environment variable TEMP is $env:TEMPcls"
Write-Host "The current path of the script is $PSScriptroot"
The file tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "my script task",
"type": "shell",
"windows": {
"command": "pwsh -f dosomething.ps1"
},
"problemMatcher": []
}
]
}
Linking the launch.json with task.json

After pressing F5
