+ 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?
7 Answers
+ 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.
+ 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.
+ 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())
+ 2
Lothar thanks
I was just curious what was going behind the screen
+ 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.
+ 1
Sololearn creates file in temporary store like cache and It will cleared after exit. Not exist in server...
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.