每一次都清除原有文件内容,再写入新内容。以 w 方式打开文件只能在打开的时候覆盖原有内容。
1
simon7 Oct 13, 2015 via iPhone
w+
|
2
heqingpan Oct 13, 2015
fobj=open("filename","a")
fobj.write("msg") fobj.flush() fobj.close() |
3
SErHo Oct 13, 2015
r+
f.seek(0) f.write("...") f.truncate() 必须保证文件存在 |
4
eightqueen OP @heqingpan 不想反复打开文件、关闭文件,我这个操作有可能重复多次。
|
5
sNullp Oct 14, 2015
seek()
|
6
eightqueen OP @sNullp 谢谢
|