0
Anyone knows how to open, read and write a text file in python on sololearn
2 Respostas
+ 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.
+ 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)