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:\Workingdirectory\Folder1: VsCode says, D:\Workingdirectory. Running it in console: D:\Workingdirectory\Folder1. Direct path is not an option. How fo i fix it? Thanks in advance!
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:
"cwd": "${fileDirname}"
Comments
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
1 Comment
Community
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
