我有一个文本文件,里面有很多我需要的数据之前的调试信息。我正在尝试使用Python3重写输出,以便文件以特定的JSON标记开头。我尝试使用这个解决方案Remove string and all lines before string from file,但是输出文件为空,所以我认为它没有找到JSON标记。
以下是我的代码:
以下是我的代码:
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)