我有一個文本文件,里面有很多調(diào)試信息,在我需要的數(shù)據(jù)之前。我正在使用 python3 嘗試重寫輸出,以便文件以特定的 json 標(biāo)記開頭。我試圖使用這個解決方案從文件 python 中刪除字符串和字符串之前的所有行,但我得到一個空的輸出文件,所以我認(rèn)為它沒有找到 json 標(biāo)簽。這是我的代碼:tag = '"meta": ['tag_found = False with open('file.in',encoding="utf8") as in_file:with open('file.out','w',encoding="utf8") as out_file: for line in in_file: if tag_found: if line.strip() == tag: tag_found = True else: out_file.write(line)任何幫助表示贊賞。
從文本文件中刪除所有行直到特定字符串 - python3
慕桂英3389331
2021-06-30 13:52:05