Debugging Python code in VS Code with arguments passed from the command line is a straightforward process. Here are the steps you can follow:
1. Open the Python file that you want to debug in VS Code.
2. Set breakpoints in the code where you want to pause and inspect variables.
3. Open the Debug panel in VS Code by clicking on the Debug icon in the Activity Bar or by pressing `Ctrl+Shift+D` on Windows or `Cmd+Shift+D` on Mac.
4. Click on the "create a launch.json file" button and select "Python" as the environment.
5. In the launch.json file that opens, modify the "args" attribute to include the command-line arguments you want to pass to the Python script. For example:
```
"args": ["arg1", "arg2"]
```
Replace "arg1" and "arg2" with the actual arguments you want to pass.
NOTE: Add the below property in the launch.json file.
"purpose": ["debug-in-terminal"]
6. Save the launch.json file.
7. Start the debugging process by clicking on the "Start Debugging" button in the Debug panel or by pressing `F5`.
8. The code execution will pause at the first breakpoint. Use the Debug Console to inspect variables, and use the Debug toolbar to step through the code and continue the execution.
That's it! You can now debug your Python code with arguments passed from the command line in VS Code.
Comments
Post a Comment