path = r'D:juhexieyinewdata2.txt'f = open(path,'w')#写文件#1、将信息写入缓冲区f.write("sunck is a good man")#2、刷新缓冲区#直接把内部缓冲区的数据立刻写入文件,而不是被动的等待自动刷新缓冲区写入(关闭文件、缓冲区满)f.flush()f.close()with open(path,'a') as f2: f2.write('good man')