【发布时间】:2023-03-29 02:12:02
【问题描述】:
我正在尝试使用 VS 代码和 python 调试程序,但是当我尝试修改 json 以接受 arg 时,它给了我一个无效的语法问题。 我试图按照 MS 中的这个链接进行调试:https://code.visualstudio.com/docs/python/debugging 但我没有得到任何地方.. 我使用默认格式并添加了我的 arg:
{
// 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}",
"args": [
"..\\4\\shopping\\shopping.csv"
],
"console": "integratedTerminal"
}
]
}
我尝试将其移动到不同的文件夹(在本例中为 \4),但我也尝试在工作区和购物文件夹中但没有成功 有人可以帮助我了解我哪里出错了吗? 谢谢
编辑 1:
添加更多细节:
这是完整的错误信息:
PS C:\Users\Carlo\source\repos\CS50AI\4\.vscode> & 'python' 'c:\Users\Carlo\.vscode\extensions\ms-python.python-2020.11.371526539\pythonFiles\lib\python\debugpy\launcher' '50282' '--' 'c:\Users\Carlo\source\repos\CS50AI\4\.vscode\launch.json'
Traceback (most recent call last):
File "C:\Users\Carlo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Carlo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\Carlo\.vscode\extensions\ms-python.python-2020.11.371526539\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Carlo\.vscode\extensions\ms-python.python-2020.11.371526539\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\Carlo\.vscode\extensions\ms-python.python-2020.11.371526539\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Users\Carlo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 264, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "C:\Users\Carlo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 239, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "c:\Users\Carlo\source\repos\CS50AI\4\.vscode\launch.json", line 2
// Use IntelliSense to learn about possible attributes.
^
SyntaxError: invalid syntax
不,我没有在 python 中获取 sys.argv
【问题讨论】:
-
您在哪里遇到了无效的语法问题?当您打开 launch.json 时,您为 args 添加的行会突出显示?
-
你在python脚本里面得到
sys.argv中的参数吗 -
编辑帖子以回答更多信息
-
你使用的是什么版本的 VS Code? (帮助 > 关于)。我可以将您的 launch.json 与 1.51.1 版本一起使用
-
1.51.1(用户设置)
标签: python json python-3.x debugging visual-studio-code