Reputation: 39
I got an error.
FileNotFoundError: [Errno 2] No such file or directory:'Users/bea/Desktop/iSight/Webservertesting/json/data1.json'
This is the code that I was running. Could you please help me fix this error.
import json
def writeToJSONFile(path, fileName, data):
filePathNameWExt = path + '/' + fileName + '.json'
with open(filePathNameWExt, 'r') as fp:
json.dump(data, fp)
fp.write(data)
writeToJSONFile("Users/bea/Desktop/iSight/Webservertesting/json", "data1", "book")
Upvotes: 0
Views: 2423
Reputation: 541
Te problem here is you need to change the 'r' to 'a' or 'w'
def writeToJSONFile(path, fileName, data):
filePathNameWExt = path + '/' + fileName + '.json'
with open(filePathNameWExt, 'a') as fp:
json.dump(data, fp)
fp.write(data)
writeToJSONFile("Users/bea/Desktop/iSight/Webservertesting/json", "data1", "book")
The reason for this is:
Upvotes: 2