会遍历文件夹下面的txt,检查第一列是否都为0
import os
folder_path = 'G:\CF-data\data_cfphone\labels-0'
def print_nonzero_first_column(file_path):
with open(file_path, 'r') as file:
for line in file:
columns = line.strip().split()
if columns and float(columns[0]) != 0:
print(file_path)
break
def process_folder(folder):
for root, dirs, files in os.walk(folder):
for file in files:
if file.endswith('.txt'):
file_path = os.path.join(root, file)
print_nonzero_first_column(file_path)
if __name__ == "__main__":
process_folder(folder_path)