Visual Studio Code: run Python file with arguments

前端 未结 7 812
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 02:00

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

7条回答
  •  广开言路
    2021-02-04 02:24

    If you don’t have a task.json file in your project you can create a new one with press Ctrl + Shift + B. Then choose the first option showing to you then replace all of them with the below:

    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Run Python with argument",
                "type": "shell",
                "command": "python PROGRAM_NAME.py ARG1 ARG2 ...",
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

    Otherwise add the above configuration in your existed tasks.json file.

    Replace PROGRAM_NAME in the above configuration with your program name and ARG1 ARG2 ... indicate your specific arguments.

    After all, you can execute your created task with Ctrl + Shift + B and choose the new "Run Python with argument" task.

提交回复
热议问题