【发布时间】:2015-10-16 05:11:48
【问题描述】:
这个程序的目的是在一个数据文件中退格三次:
ofile = open(myfile, 'r')
file = open(myfile, 'r')
with open(myfile, 'rb+') as filehandle:
filehandle.seek(-3, os.SEEK_END)
filehandle.truncate()
然后我尝试通过切换到“写入”功能在此之后添加其他文本:
ofile = open(myfile, 'r')
file = open(myfile, 'r')
with open(myfile, 'rb+') as filehandle:
filehandle.seek(-3, os.SEEK_END)
filehandle.truncate()
ofile = open(myfile, 'w')
ofile.write('*')
但是,这会覆盖整个数据集并在空白文档上仅写入“*”。如何在不删除其余内容的情况下添加到文件中?
【问题讨论】:
标签: python filehandle