Visual Studio Code: run Python file with arguments

前端 未结 7 813
被撕碎了的回忆
被撕碎了的回忆 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:22

    Maybe this will do what you want: create a python.bat file in your %PATH% that points to python.exe:

    C:\Users\joecoder\AppData\Local\Programs\Python\Python37\python.exe %*
    

    Then use a Visual Studio Code terminal window (you can open a new one from the Terminal tab at the top of Visual Studio Code) to change directory to where your .py file resides, and run as normal:

    PS C:\Users\joecoder> cd vscode\python
    PS C:\Users\joecoder\vscode\python> python test.py 1 2 3
    

    Of course this runs outside of Visual Studio Code, so be sure to write out changes after edits and you'll have to use print() style debugging.

提交回复
热议问题