0

Anyone knows how to open, read and write a text file in python on sololearn

3rd Jun 2020, 8:32 AM
Kirubanandan N
Kirubanandan N - avatar
2 Respuestas
+ 2
The same way you would open, read/write (and optionally) close text files using Python anywhere else. The difference being that the file will not be persistent, file will be deleted once the code execution completed. (Edit) You should specify Python in your thread tags for context clarity.
3rd Jun 2020, 8:52 AM
Ipang
+ 2
import os os.chdir(path_to_file) with open(filename) as f: text = f.read() # print all text print(text) s = 'I love python' with open(filnename, 'w') as fw: for i in range(50): # write i love python 50 times fw.write(s)
3rd Jun 2020, 8:58 AM
Slick
Slick - avatar