Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

File not found error on creating a new file and writing in it

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’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading