我在python中读取文件有愚蠢的问题。
我的have文件夹是'a',其中包含我的test.py和文件test.json以供读取
我的test.py看起来像这样:
config_path = 'test.json'
with open(config_path) as config_buffer:
config = json.loads(config_buffer.read())
我站在文件夹“ a”之外,然后运行命令:
python a\test.py
控制台为我返回错误:
FileNotFoundError: No such file or directory: 'test.json'
我尝试使用pathlib使用绝对文件路径:
config_path = Path('end2end.json').absolute()
with open(config_path) as config_buffer:
config = json.loads(config_buffer.read())
但是它仍然向我返回错误:
FileNotFoundError: No such file or directory: 'D:\\test.json'
任何人都可以帮助我获取确切的目录文件吗?