‘’’
取出类别标签为1-5
‘’’
import os
from shutil import copy
path = r"C:/Users/Admin/Desktop/STUDY/result/result/"
save = r"C:/Users/Admin/Desktop/STUDY/result/1/"
files = os.listdir(path)
for txt in files:
print(txt)
with open(path+txt) as f:
lines = f.readlines()
# print(lines)
# del f
data = []
for line in lines:
cls = line.split()[0]
# print(cls)
# if int(cls) ==0 or int(cls) ==1 or int(cls) ==2 or int(cls) ==3 or int(cls) ==4:
if int(cls) ==0:
data.append(line)
print(data)
if data != []:
with open(save+txt,'w') as f1:
f1.writelines(data)
del f1