【转】python删除文件里包含关键词的行

2022-11-24,,,,

import shutil
with open('/path/to/file', 'r') as f:
with open('/path/to/file.new', 'w') as g:
for line in f.readlines():
if '/local/server' not in line:
g.write(line)
shutil.move('/path/to/file.new', '/path/to/file')

 

原文链接:https://segmentfault.com/q/1010000000124564

【转】python删除文件包含关键词的行的相关教程结束。

《【转】python删除文件里包含关键词的行.doc》

下载本文的Word格式文档,以方便收藏与打印。