python - 使用 Pythonq 在 VSCode 中传递“args”时语法无效:“...”
问题描述
将命令行参数传递给我正在调试的 python 脚本时,我遵循以下指示
https://github.com/Microsoft/vscode/issues/28059
通常我会使用不需要dir
前缀的 dir 参数启动脚本
例如:python script.py c:\output_folder
启动脚本并设置c:\output_folder
为 dir 变量
所以按照网上的指示,我在launch.json
文件中有以下内容
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"preLaunchTask": "shellCommand",
"console": "integratedTerminal",
"args": ["c:\\output_folder"]
}
]
}
尝试在 VS Code 中调试 python 文件时,出现此错误:
Traceback (most recent call last):
File "C:\python\portablepython\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\python\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\wheels\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\wheels\debugpy/..\debugpy\server\cli.py", line 429, in main
run()
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2020.3.71659\pythonFiles\lib\python\debugpy\wheels\debugpy/..\debugpy\server\cli.py", line 266, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\python\lib\runpy.py", line 261, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "C:\python\lib\runpy.py", line 236, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "C:\code\.vscode\launch.json", line 2
// Use IntelliSense to learn about possible attributes.
^
SyntaxError: invalid syntax
它显然给出了一个错误,launch.json
所以我知道它不在 python 脚本中
为什么"args"
线路不工作launch.json
?
谢谢
解决方案
因为您已"program": "${file}"
设置它意味着调试器将启动您当前打开的文件。根据回溯,您似乎正在以launch.json
open 作为当前文件启动调试器。切换到您要调试的文件,它应该可以正常工作。
推荐阅读
- jquery - Jquery滚动顶部动画不会到达所需的位置/向上滚动
- python-3.x - 如果python中的值高于1pa,我们如何缩放wav文件中的值?
- angular - Angular Reactive Form Select 下拉菜单有一个空选项
- rust - 无法编译 rust 程序
- python - Blender bpy.data.materials.append(mat) 两次应用 mat
- r - 处理 R 中的递归深度限制
- javascript - 使用带有 webpack javascript 的 firebase 托管
- ios - iOS全文编辑器实现示例
- android - 将数据放入 ExpandableListview
- php - 将结构为多维数组的字符串转换为数组