File Not Found Error On Creating A New File And Writing In It

- 1 answer

I am trying to create a new file and write on it . but when I am doing something like this I am getting file not found error. seems I am missing something which I can't figure out .

data = {
    "table_name": "name",
file_path = '/tmp/myfile.json'
with open(file_path + '.json', 'w') as f:
    json.dump(data, f, indent=2)

[ERROR] FileNotFoundError: [Errno 2] No such file or directory: '/tmp/myfile.json'



are you trying to run this on Windows by any chance? Or a *nix system where you don't have access to /tmp?

For me, this script runs fine on a Ubuntu and MacOS (although the created file is /tmp/myfile.json.json instead of /tmp/myfile.json because of the + '.json' in your script), but not on Windows.