In my workingdirectory I have many folders with a python script modifying data in the same folder.
When running Python in VsCode I need to give a relative path from the working directory into the folder. For example using os.getcwd(), test.py is in D:WorkingdirectoryFolder1: VsCode says, D:Workingdirectory. Running it in console: D:WorkingdirectoryFolder1.
Direct path is not an option.
How fo i fix it?
Thanks in advance!
Question posted in Visual Studio Code
View the official documentation.
View the official documentation.
2
Answers
This is caused by vscode using workspace as root floder.
This will lead to a problem. When you use the
os.getcwd()
method in the deep directory of the workspace, you will still get the workspace directory.You can open your settings and search Python > Terminal: Execute In File Dir then check it.
You can also use debug mode and add the following to your launch.json:
If your external terminal works normally, you can also use it as default in vscode by changing the option [Terminal: Explorer Kind] to external.
screenshoot