Is there an easy way to run a Python file inside Visual Studio Code with arguments?
I know I can add a custom configuration in the launch.json
file with the
You can add a custom task to do this. This deals with the tasks.json
. You can add a default tasks.json file for you project (project folder). Follow these steps. Keyboard press Ctrl + Shift + B. It will prompt the following popup
Click on the Configure Build Task If there is already a custom tasks.json file created in the following location .vscode/tasks.json
editor will open it. If not, it will give a drop down of suggestions of already existing task runners.
Our intention is to create a custom tasks.json file for our project, so to create one we need to select the Others option from the drop down. Check the screenshot below.
Once you select the Others option, you could see a default tasks.json file will get created from the root directory of the project to the location .vscode/tasks.json
. Below is an example of tasks.json.
Now edit the tasks.json file to support Python.
"echo"
to "Python"
"Always"
["Hello World"]
to ["${file}"]
(filename)problemMatcher
You can now open your .py file and run it nicely with the shortcut Ctrl + Shift + B.