I have a folder named study
in which I have a JSON file named data.json
but when I'm trying to open it in a python script located in the same folder, I get FileNotFoundError: [Errno 2] No such file or directory: 'data.json'
.
When I use the full, absolute path to data.json
, however, it works.
How do I fix this such that I can specify the path of data.json
to be in the same folder as my .py file?
Here is my code:
import json
data = json.load(open("data.json"))
def translate(w):
return data[w]
word = input("Enter word: ")
print(translate(word))