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/1…
原文 : http://www.cnblogs.com/SophiaTang/archive/2012/01/16/2323467.html import os 删除文件: os.remove() 删除空目录: os.rmdir() 递归删除空目录: os.removedirs() 递归删除目录和文件(类似DOS命令DeleteTree): 方法1:自力更生,艰苦创业 # Delete everything reachable from the directory named in 'top',…
import os 删除文件: os.remove() 删除空目录: os.rmdir() 递归删除空目录: os.removedirs() 递归删除目录和文件(类似DOS命令DeleteTree): 方法1:自力更生,艰苦创业 # Delete everything reachable from the directory named in 'top',# assuming there are no symbolic links.# CAUTION: This is dangerous! …