Maison >développement back-end >Tutoriel Python >Comment définir le répertoire de travail pour un débogage Python efficace dans VS Code ?
Setting the Working Directory for Python Debugging in VS Code
For seamless debugging in VS Code, specifying the working directory is crucial. Here's how to achieve it:
Dynamic Working Directory via launch.json
Utilize the "cwd" option in launch.json to set the working directory to the location of the open Python file. This dynamic approach ensures that the correct directory is always used:
<code class="json">"cwd": "${fileDirname}"</code>
Note: Ensure capitalization and correct spelling of "fileDirname."
Additional Configuration (Optional)
Depending on your debugging method, you may need to include the "purpose" option:
<code class="json">"purpose": ["debug-in-terminal"]</code>
This option is necessary if using the play button or "Run and Debug" sidebar option.
Example Launch.json Configuration
For debugging with the Python: Current File (Integrated Terminal) option, your launch.json might resemble:
<code class="json">{ ... "configurations": [ { "name": "Python: Current File (Integrated Terminal)", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "cwd": "${fileDirname}", "purpose": ["debug-in-terminal"] }, ... }</code>
Creating a launch.json File
If you don't have a launch.json file, follow these steps:
Alternative Method
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!