Home > Mobile >  Passing argument/key pair to vscode Python debugger separated with an equal sign
Passing argument/key pair to vscode Python debugger separated with an equal sign

Time:08-10

For management of my config files, I'm using Hydra which requires passing additional arguments using a plus and then an equal sign between the argument and its value, e.g.

python evaluate.py ' model_path="logs/fc/version_1/checkpoints/epoch=1-step=2.ckpt"'

Above I'm also using quotes to escape the equal signs in the value.

I want to pass this in vscode to launch.json to the args field; however, I don't know how to do it properly because typically the argument and value parts are separated by a space and not an equal sign as for Hydra. So the following doesn't work:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "args" : [" model_path", "logs/fc/version_1/checkpoints/epoch=1-step=2.ckpt"]
    }
  ]
}

How should I change args to get it right?

CodePudding user response:

If you need to pass arguments to the Python interpreter, you can use the pythonArgs property.

Use the following syntax:

"pythonArgs": ["<arg 1>", "<arg 2>",...]

If you pass paired arguments with args:

"args" : ["--port", "1593"]

There are more details on launch.json configuration here.

CodePudding user response:

This may not be the most elegant solution but it works if we pass everything as a single argument (no comma inbetween) like this:

"args" : [" model_path='logs/fc/version_7/checkpoints/epoch=19-step=3700.ckpt'"]

  • Related