如何遍历文件夹中的所有.txt文件,并判断有无字段
import os
path=r'C:\Users\22828\Desktop\PyTorch-YOLOv3-code\data\face_mask\labels'
# print(len(os.listdir(path))) # 956
for item in os.listdir(path):
path_item=os.path.join(path,item)
with open(path_item,'r') as f:
list=f.readlines()
if len(list)<1:
print(list)
print('---')