0

What do I need to put in this file in order to run my program. From the command line normally I navigate to the folder (as my test file is there too) and type:

python main.py test_file.xlsx

So my python script is called main.py and I am sending an excel file as an argument. I can't work out what you are supposed to put in the launch.json file to get it to work I found the args bit from another post, but I have no idea if I have done it correctly as vscode is objecting to its own default launch file comment?:

{
    // 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"
            "console": "integratedTerminal"
        }
    ]
}

Completely lost with this, why is there not some documentation around this?

3
  • 1
    it's a json file, you can't put comments in it. Remove those 3 lines. Also there is a extension called code runner or something like that in vscode which you can use to run files of various different languages Commented Aug 20, 2019 at 12:23
  • You need to specify the "args" bit. Right now you just have the key with no value and no comma between it and "console" Commented Aug 20, 2019 at 12:27
  • VSCode uses a different JSON standard, which allows for comments. See my answer re the args bit. Commented Aug 20, 2019 at 12:27

1 Answer 1

1

Let's start from the top:

The JSON you have pasted above is not valid - objects must be key-value pairs. Your args key does not have a value.

args is an array of strings that are passed in to the command in your configuration. In your case this would be ["${workspaceFolder}/main.py"] if your main is in the root directory of the workspace.

To have a nice dynamic list of secondary arguments (in your case files) you can use the runtimeArgs key. It is also a list of strings, in your case it would be ["test_file.xlsx"]

Documentation about the VSCode debugger can be found here: https://code.visualstudio.com/docs/editor/debugging

Hope this helps :)

Sign up to request clarification or add additional context in comments.

1 Comment

That's my bad, I forgot to remove all the args line from what I had tried previously. Your answer was correct, all I was missing was the square brackets, I didn't know it was taking in a list. But it works, thank you very much for your prompt reply.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.