Python 23 Programming Tutorial - How to Read and Write Files

328 ワード

I read in the comments that a lot of people were having trouble
fw = open('sample.txt', 'w')
fw.write('Writing some stuff in my text file
') fw.write('I like bacon
') fw.close() fr = open('sample.txt', 'r') text = fr.read() print(text) fr.close()