Pycharm, VScode, file relative path

The difference between the current folder path of Pycharm and VScode

Usually, VScode and Pycharm are used alternately. One is lightweight and the other is more convenient for debugging. But today I suddenly found that the file that can be run in vscode reported an error in pycharm. After debugging for a long time, pay attention to avoid pits.
insert image description here
In the above file structure [KKKK]–>[111]–>[xxx.py], run the os.getcwd() command in VScode and Pycharm respectively, and get the following results: Vscode: shows the
main
directory of the opened folder
insert image description here

Pycharm
shows the folder directory where the current file is located
insert image description here
Reason : vscode defaults to the root path of the project as the current path

Solution : After trying, the methods given on the Internet such as adding [${fileDirname}] and ticking the box in the figure below cannot solve this problem.

insert image description here
insert image description here

Finally, by adding the following statement in the launch.json file, the relative path in Vscode can be consistent with Pycharm.

insert image description here

Guess you like

Origin blog.csdn.net/m0_46366547/article/details/128738915