I'm getting an error when attempting to read a JSON file:
def get_mocked_json(self, filename):
f = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../fixtures', filename)
if os.path.exists(f) is True:
return json.loads(f.read())
else:
return 'mocked.json'
This is the error:
if os.path.exists(f) is True:
----> return json.loads(f.read())
else:
return 'mocked.json'
AttributeError: 'str' object has no attribute 'read'
Any help in what I am doing wrong would be much appreciated.
' '.join()results in a string type. so you're performing.read()on a stringf- is your string with path, you can not callread()method on string