I am trying to read a file in python. This is the code I am using:
# test script
import csv
import json
import os
def loadKeys(key_file):
json_keys=open(key_file).read()
data = json.loads(json_keys)
return data["api_key"],data["api_secret"],data["token"],data["token_secret"]
KEY_FILE = 'keys.json'
print(os.listdir(os.path.dirname(os.path.realpath(__file__))))
api_key, api_secret, token, token_secret = loadKeys(KEY_FILE)
However it returns the following error
->print(os.listdir(os.path.dirname(os.path.realpath(__file__))))
['.DS_Store', 'keys.json', 'script.py', 'test.py']
->api_key, api_secret, token, token_secret = loadKeys(KEY_FILE)
IOError: (2, 'No such file or directory', 'keys.json')
Is there anything I am doing wrong?