【发布时间】:2018-06-10 21:13:30
【问题描述】:
我想使用以下代码读取文件:
import os
DIRNAME = os.path.dirname(__file__)
mydir=os.path.join(DIRNAME,'test.json')
myfile = open(mydir) # alice.txt is in the same dir as foo.py
mytxt = myfile.read()
myfile.close()
我有以下错误:
IOError: [Errno 2] No such file or directory: 'C:/Users/user/Documents/MyTest\\test.json'
我在那个目录中有test.json,但我不确定为什么会出现这个错误。可能是什么问题?
【问题讨论】:
标签: python json python-2.7