[英]VS Code launch.json into an actual command
I want to make a Python script that transforms a part of VS Code launch.json
into a normal command for a terminal.我想制作一个 Python 脚本,将 VS Code
launch.json
的一部分转换为终端的正常命令。 I need it to communicate with non-VSCode users.我需要它来与非 VSCode 用户交流。 Here is the example:
这是示例:
import json
launch_json = '''
{
"name": "temp",
"type": "python",
"request": "launch",
"program": "script.py",
"console": "integratedTerminal",
"justMyCode": false,
"args": ["abcd",
"--log", "log.txt"],
"env": {"CUDA_VISIBLE_DEVICES":"0"},
}
'''
d = json.loads(launch_json)
command = d["program"] + " " + " ".join(d["args"])
print(command)
If I run it, I have the following error:如果我运行它,我会遇到以下错误:
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 12 column 9 (char 344)
How do I make the script?如何制作脚本?
There is an extra comma at the end of launch_json
launch_json
末尾多了一个逗号
{
"env": {"CUDA_VISIBLE_DEVICES":"0"}, <- should not be here
}
so just replace it with所以只需将其替换为
{
"name": "temp",
"type": "python",
"request": "launch",
"program": "script.py",
"console": "integratedTerminal",
"justMyCode": false,
"args": ["abcd",
"--log", "log.txt"],
"env": {"CUDA_VISIBLE_DEVICES":"0"}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.