+ 1

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?

15th May 2022, 4:17 PM
Harsha S
Harsha S - avatar
7 Antworten
+ 6
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.
15th May 2022, 4:23 PM
Paul
Paul - avatar
+ 6
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.
15th May 2022, 5:10 PM
Lothar
Lothar - avatar
+ 3
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())
15th May 2022, 5:26 PM
Paul
Paul - avatar
+ 2
Lothar thanks I was just curious what was going behind the screen
15th May 2022, 5:11 PM
Harsha S
Harsha S - avatar
+ 2
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.
16th May 2022, 9:13 PM
James
James - avatar
+ 1
Sololearn creates file in temporary store like cache and It will cleared after exit. Not exist in server...
15th May 2022, 4:24 PM
Jayakrishna 🇮🇳
0
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.
16th May 2022, 5:08 AM
Harsha S
Harsha S - avatar