I am in Terminal on mac and I am learning how to open, close, read, delete files.
When I set
f = open("sample.txt", 'w')
and then hit f.truncate()
the contents delete.
However, when I do f.write()
it does not update in the text file. It only updates after I do f.truncate()
.
I was wondering why this happens (I thought f.truncate()
was supposed to delete the text!)? Why doesn't the text editor update automatically when I type in f.write()
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…