Kev*_*chs 3 python debugging command-line-arguments visual-studio-code
我知道如何在 launch.json 中传递固定参数,例如在 Visual Studio Code 中,如何在 launch.json 中传递参数。我真正需要的是一个提示,我可以在其中为发生变化的参数给出一个值。
另外,我的论点是一个(数据)目录,其中有一个非常丑陋的长绝对路径。我真的希望能够将工作目录设置为包含每个单独数据目录的路径,因此我只需要提供相对目录路径,即仅提供目录名称。
我正在使用 Python,在 Windows(不是我的选择)上使用 VS Code 1.55.2(也不是我的选择)。
您可以使用输入变量
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File with arguments",
"type": "python",
"request": "launch",
"program": "${file}",
"args": [
"--dir",
"/some/fixed/dir/${input:enterDir}"
]
}
],
"inputs": [
{
"id": "enterDir",
"type": "promptString",
"description": "Subdirectory to process",
"default": "data-0034"
}
]
}
Run Code Online (Sandbox Code Playgroud)
您可以将 放置${input:enterDir}在任务中的任何字符串中,"configurations"例如"cwd"属性。
Command Variable如果您想从列表中选择一个目录,因为它是动态的,您可以使用具有命令pickFile的扩展
命令变量 v1.36.0 支持fixed文件夹规范。
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File with arguments",
"type": "python",
"request": "launch",
"program": "${file}",
"args": [
"--dir",
"${input:pickDir}"
]
}
],
"inputs": [
{
"id": "pickDir",
"type": "command",
"command": "extension.commandvariable.file.pickFile",
"args": {
"include": "**/*",
"display": "fileName",
"description": "Subdirectory to process",
"showDirs": true,
"fromFolder": { "fixed": "/some/fixed/dir" }
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
在类 Unix 系统上,您可以将文件夹包含在includeglob 模式中。在 Windows 上,您必须使用 将fromFolder目录路径转换为可用的 glob 模式。如果您有多个文件夹,则可以使用该predefined属性。
| 归档时间: |
|
| 查看次数: |
3081 次 |
| 最近记录: |