我做这样的事情:
import json
data = { "id": 1 }
with open('~/Desktop/data.json','w') as f:
json.dump(data,f)
但我收到此错误:
FileNotFoundError: [Errno 2] No such file or directory: '...Desktop/data.json'
实际上,我还没有预先在data.json
中创建Desktop
文件,但是我认为这就是我上面的代码应该做的。
我该怎么做?