crl6904
crl6904

Reputation: 1

VS code - python - debug format issue

I am trying to debug a program with VS code and python but when I try to modify the json to accept an arg it gives me an invalid syntax issue. I tried to follow this link in MS regarding debugging: https://code.visualstudio.com/docs/python/debugging but am not getting anywhere.. I am using the default format and added my 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"
        }
    ]
}

I tried to move it into a different folder (In this case in \4) but I have also tried in the workspace and the shopping folder but without success Can someone help me understand where I am going wrong? thanks

EDIT 1:

adding more details:

this is the full error message:

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

no i do not get sys.argv in python

Upvotes: 0

Views: 492

Answers (2)

Jill Cheng
Jill Cheng

Reputation: 10354

According to the information you provided, I reproduced the problem in the terminal:

enter image description here

Reason: When using debugging, we need to open the script that needs to be executed instead of staying in the "launch.json" file.

Solution: Open the python script to be executed and debug it.

result:

enter image description here

Reference: Troubleshooting in VSCode.

Upvotes: 1

Heck Codes
Heck Codes

Reputation: 161

Just remove the first three lines (comments).

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "args": [
            "..\\4\\shopping\\shopping.csv"
        ],
        "console": "integratedTerminal"
    }
]}

Upvotes: 0

Related Questions