delete specific lines in a set of files in a folder

版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/watson243671/article/details/38471529
import os 

myinst = ['foo','bar']

def wipe_lines(folder):
    for (dirpath, dirnames, filenames) in os.walk('/Users/faramir/git/'+ folder):
        for filename in filenames:
            f = open(os.sep.join([dirpath, filename]),"r")
            lines = f.readlines()
            f.close()
            f = open(os.sep.join([dirpath,filename]),"w")
            for line in lines:
                if not line in copyright:
                    f.write(line)

for x in ['mos','unittest']:
    wipe_lines(x)


猜你喜欢

转载自blog.csdn.net/watson243671/article/details/38471529