# 删除特定字段行数
def deleteLine(filename):
with open(c,'r') as r:
lines=r.readlines()
with open(c,'w') as w:
for l in lines:
# delete the line contain 'film' 'weight' 'height' 'banner'
if 'film' not in l and 'width' not in l and 'height' not in l and 'gaussian' not in l and 'banner' not in l:
w.write(l)
# 找到当前目录所有xml文件
import os
# find the current files in '.'
filelist = os.listdir(os.getcwd())
for c in filelist:
if os.path.isfile(c) and c.endswith('.xml'):
print(c)
deleteLine(c)
import os
filelist = os.listdir(os.getcwd())
for c in filelist:
if os.path.isfile(c) and c.endswith('.xml'):
print(c)
#os.system('这里填写终端操作命令 {}'.format(c))
# for example 删除制定文件
os.system('rm -rf {}'.format(c))
参考