python 在末尾增加一个字符串,python - Python File.write在末尾添加额外的字符串 - SO中文参考 - www.soinside.com...
我正在使用python(3.6)更新文本文件,并打開r +with open(f+'.play', 'r+') as f2:
play = f2.read()
result = manipulate(play)
print(result)
f2.seek(0, 0)
f2.write(result)
通過這樣做,我得到了意外的結(jié)尾部分ap:Envelope>
當然,多余的部分是在第一次關(guān)閉之后>
我通過操作解決了這個問題>with open(f+'.play', 'r+') as f2:
play = f2.read()
result = manipulate(play)
print(result)
f2.seek(0, 0)
f2.truncate()
f2.write(result)
在這種情況下,寫操作符合我的預期。
但是,我不明白為什么需要截斷,seek(0,0)還不夠嗎?因為在我看來,seek(0)+ write應該以適當?shù)姆绞礁采w整個內(nèi)容,所以我在這里缺少什么知識?
我正在使用python(3.6)更新文本文件,其中open r +的open(f +'。play','r +')為f2:play = f2.read()result = handle(play)print(result) f2.seek(0,0)f2.write(result)by ...
總結(jié)
以上是生活随笔為你收集整理的python 在末尾增加一个字符串,python - Python File.write在末尾添加额外的字符串 - SO中文参考 - www.soinside.com...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 离骚翻译及原文
- 下一篇: 电脑版吃鸡类的(电脑版吃鸡都有哪些)