Visual Studio Code: run Python file with arguments

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

    Another option is you can run your python program from the commandline via

    python3 -m debugpy --wait-for-client --listen localhost:5678 myprogram.py
    

    Then you can use a Python: Remote Attach launch.json configuration to connect to the program. It means an extra step every time to you turn on your program: run the program on the CLI then attach debugger, but it does make specifying the arguments more fluid.

    To make things even simpler, you could put the above in a bash script and pass through args from CLI to python:

    start.sh "my arg that changes all the time"
    

    Then attach via "Remote Attach".

提交回复
热议问题