0
When i use open function to open my file, it shows No such file
what should i do
6 Answers
+ 4
You can write and read files on SoloLearn PlayGround. But you have to do it in this sequence: First write, then read. This has to be in the same program, as the created file will resist only during the execution of the code, then it will be removed.
See the following code that writes the file txt3.txt in the same directory as the source code is stored. The file looks like that:
Sam Black 24
Susan Black 18
Simon Smith 28
Sandra Waters 08
Then the new created file will be opend for reading, and should give an output for each subject in a new line.
tx0 = ('Sam Black 24', 'Susan Black 18', 'Simon Smith 28', 'Sandra Waters 08')
f = open('txt3.txt','w')
for i in tx0:
f.write(f'{i}\n')
f.close()
f = open('txt3.txt','r')
words = []
temp = open('txt3.txt','r').read().splitlines()
for i in temp:
words.append(i.split(' '))
for j in words:
for k in j:
print(k)
f.close()
0
Unfortunately opening files isn't supported in Sololearn. For that you have use IDE.
0
Also in IDE
0
Which IDE?
0
python IDE and also in spyder
0
You have place the file in correct folder where it can be recognised by python ide.