0

When i use open function to open my file, it shows No such file

what should i do

7th Apr 2020, 7:39 AM
aryan kumar
aryan kumar - avatar
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()
7th Apr 2020, 10:55 AM
Lothar
Lothar - avatar
0
Unfortunately opening files isn't supported in Sololearn. For that you have use IDE.
7th Apr 2020, 7:45 AM
Tricker
0
Also in IDE
7th Apr 2020, 7:47 AM
aryan kumar
aryan kumar - avatar
0
Which IDE?
7th Apr 2020, 7:48 AM
Tricker
0
python IDE and also in spyder
7th Apr 2020, 7:49 AM
aryan kumar
aryan kumar - avatar
0
You have place the file in correct folder where it can be recognised by python ide.
7th Apr 2020, 7:51 AM
Tricker