1.读取文件
import os
import sys
text_files_dir = '/home/wgb/Downloads/images'
file_text = text_files_dir + 'name.txt'
f = open(file_text, 'w')
class_name = 0
for filename in os.listdir(text_files_dir):
f1 = text_files_dir + "/" + filename
class_name += 1
print(filename, class_name)
for filename2 in os.listdir(text_files_dir):
f2 = f1 + '/' + filename2
f.write(f2 + ' ' + str(class_name) + '\n')