使用continue跳過本次寫循環(huán)就可以了
#文本內(nèi)容Yesterday when I was young昨日當我年少輕狂The tasting of life was sweet生命的滋味是甜的As rain upon my tonguetastingI lived by night and shunned the naked light of daytasting123And only now I see how the time ran awaytasting tasting
將文本中的 tasting123刪除
with open("fileread.txt","r",encoding="utf-8") as f: lines = f.readlines() #print(lines)with open("fileread.txt","w",encoding="utf-8") as f_w: for line in lines: if "tasting123" in line: continue f_w.write(line)以上這篇python 文件操作刪除某行的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點
疑難解答
圖片精選