2

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 2

6

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.

enter image description here

You can also use debug mode and add the following to your launch.json:

"cwd": "${fileDirname}"
Sign up to request clarification or add additional context in comments.

Comments

0

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.