这个程序的目的是在一个数据文件中退格三次:
ofile = open(myfile, 'r')
file = open(myfile, 'r')
with open(myfile, 'rb+') as filehandle:
filehandle.seek(-3, os.SEEK_END)
filehandle.truncate()然后,我切换到"write“功能,尝试在此之后添加其他文本:
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('*')然而,这将覆盖整个数据集,并且只在空白文档上写入"*“。如何在不删除其余内容的情况下添加到文件?
发布于 2015-10-16 13:16:05
您需要使用append标志,而不是write。所以,ofile = open(myfile, 'a')
https://stackoverflow.com/questions/33162984
复制相似问题