Where's the missing file? | Sololearn: Learn to code for FREE!


Where's the missing file?

i created a file: https://code.sololearn.com/cgI7g2YfOm46/?ref=app i tried to read the file: https://code.sololearn.com/c5Loq2j9MPZf/?ref=app so, what's happening in the background? what did sololearn do? where did the file go?

5/15/2022 4:17:51 PM

Harsha S

7 Answers

New Answer


Harsha S , what you can do is to put both codes in one file: 1. creating / writing to a file 2. reding from the file file = open("harsha.txt", "w") file.write("harsha") file.close() file = open("harsha.txt") print(file.read()) file.close() as this will be executed in one session, you can store and access the created file. when the execution is terminated, the file is gone.


Your programs are running on a random server with a cleaned environment on sololearn. You can't save files with one program and read them with a second one.


Lothar thanks I was just curious what was going behind the screen


In the past i made a small program to see where the code was running. If you run it more than once, you will see that you are every time on a different node: import os import socket print(os.uname()) print() print(socket.gethostname())


This is a bit off topic but may be useful to you in the future. If you write to a file as you did in the example, if there were to be an exception during the file.write() call the file might not close and may leak a discriptor. Use try and finally for write and close calls. You can avoid all that by using the with statement.


Sololearn creates file in temporary store like cache and It will cleared after exit. Not exist in server...


Paul can i use this somehow to link 2 different python codes in sololearn? https://code.sololearn.com/chDn3SO5jt1V/?ref=app i think it's not possible. it's complicated.