在vscode下使用python读取路径时:
with open(classes_path) as f:
……
"classes_path": './C/d.txt'
……
显示报错:
FileNotFoundError: [Errno 2] No such file or directory: './C/d.txt'
报错原因和编辑器的工作区有关。
解决方法:
vscode打开的是文件夹,查看运行代码和该文件夹的位置关系:
从上到下依次为:vscode打开的文件夹A、运行程序所在文件夹B、运行程序读取的文件d.txt、运行文件c.py
所以应该将报错位置改为:
"classes_path": './B/C/d.txt'
即可解决问题。