【问题标题】:Pass object as a string for debugging in VSCode' launch.json file将对象作为字符串传递给 VSCode 的 launch.json 文件进行调试
【发布时间】:2021-09-14 23:47:24
【问题描述】:

我正在尝试使用 VSCode 调试器调试我的 python 模块。我准备我的launch.json 文件如下:

{
  "version": "0.2.0",
      "configurations": [
          {
              "type": "pwa-chrome",
              "request": "launch",
              "name": "Python: Current file",
              "url": "http://localhost:8081",
              "webRoot": "${workspaceFolder}",
              "runtimeArgs": ["arg1", "arg2", '{"host":"https://x.xxx.xx.xxx/console","port":443,"selfSignedCert": false}', '{"auth": {"sec": "ccccccc-dddd-eeee-ffff-gggggggggg"}}', "args3"]
          }
      ]
}

但我认为这不是传递对象'{"host":"https://x.xxx.xx.xxx/console","port":443,"selfSignedCert": false}''{"auth": {"sec": "ccccccc-dddd-eeee-ffff-gggggggggg"}}' 的正确方法。

我想将对象按原样传递到模块中,即使用单引号。有人可以帮助我以正确的方式做到这一点吗?

【问题讨论】:

  • 因为launch.json 必须在JSON format 文件中,所以不能在JSON 需要双引号的地方使用单引号,因此你不能做你想做的事。你为什么要他们呢?我想这可能是XY problem
  • ……续。如果您希望字符串嵌入双引号字符,您可以像这样转义这些字符:"{\"host\":\"https://x.xxx.xx.xxx/console\",\"port\":443,\"selfSignedCert\": false}""{\"auth\": {\"sec\": \"ccccccc-dddd-eeee-ffff-gggggggggg\"}}"
  • 谢谢,这很清楚。但只是让您知道,这就是我的程序期望输入的方式。因此我必须这样通过。在接受输入后,我可以用另一种方法来处理它们。非常感谢@martineau
  • 尴尬只是设置被存储在 JSON 格式文件中这一事实的产物。

标签: python debugging visual-studio-code vscode-debugger


【解决方案1】:

来自Debugging configurations for Python apps in Visual Studio Code

参数

指定要传递给 Python 程序的参数。的每个元素 由空格分隔的参数字符串应包含在 引号,例如:

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

在 args 中添加 '' 似乎是不可能的。

【讨论】:

    猜你喜欢
    • 2013-01-21
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 2012-07-20
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多