擅长:python、mysql、java
<p>假设stack1.txt是您发布的文件。这将写入一个新文件stack2.txt,如果“空格后的值”大于等于300,则该文件将省略“authority\u section”行。这个解决方案不需要解析json,但是它非常依赖于数据的格式是否一致。你知道吗</p>
<pre><code>import os
with open('stack2.txt','w') as new_file:
old_file = open('stack1.txt').readlines()
delete_file = False
for line in old_file:
if not (line.strip().startswith('"authority_section"') and int(line.split(':')[1].split()[1]) >= 300):
new_file.write(line)
else:
delete_file = True
if delete_file:
os.remove('stack2.txt')
</code></pre>