python读写文件问题2
txt文本中的第一行为什么会覆盖?
源程序:
f = open(r'C:\python\Blowing in the wind.txt', 'r+')
f.seek(0,0)
f.writelines("Blowin' in the wind")
f.writelines('\40 Bob Dylan \n')
f.seek(0,2)
f.writelines('\n 1962 by Warner Bros. Inc')
f.seek(0,0)
print(f.read())
f.close()
运行前文件内容:
How many roads must a man walk down
Before they call him a man
How many seas must a white dove sail
Before she sleeps in the sand
How many times must the cannon balls fly
Before they're forever banned
The answer my friend is blowing in the wind
The answer is blowing in the wind
运行后文件内容:
Blowin' in the wind Bob Dylan
wn
Before they call him a man
How many seas must a white dove sail
Before she sleeps in the sand
How many times must the cannon balls fly
Before they're forever banned
The answer my friend is blowing in the wind
The answer is blowing in the wind
1962 by Warner Bros. Inc