M
M
Mr.nobody2018-09-19 17:30:52
Python
Mr.nobody, 2018-09-19 17:30:52

How to create a temporary file and work with it in Python?

Hello. I am taking a course on Coursera, there is a task to create a temporary storage for storing data in json format. I wrote a script, everything works for me, I upload it to the server - it doesn't work, it gives an error:
Your script ended with an error FileNotFoundError: [Errno 2] No such file or directory: 'storage_path'
I read the documentation on the tempfile module, I didn't understand.
I create a file like this:

storage_path = os.path.join(tempfile.gettempdir(), 'storage.data')

storage_path file is created
Then I open it:
with open(storage_path, mode='w', encoding='utf8') as file:

and then I write, read, etc.
But it doesn't work on the server. Tell me what I'm doing wrong.
sandbox code

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question