在脚本中调用其他工具的过程中可能会产生很多的中间文件,这个时候作为一个假装有洁癖的人是必须要把他们清理干净的,因此之前做了这个函数装饰器:
def wrap_rm_add_file(f):
def rm_add_file(*args, **kwargs):
before_file = os.listdir(os.getcwd())
result = f(*args, **kwargs)
for file in os.listdir(os.getcwd()):
if file not in before_file:
os.system("rm -rf %s" % file)
return result
return rm_add_file
这样在函数执行后,装饰器会把多出来的文件全部删除,保持了目录的干净整洁。