import os path = 'E:/a_final/voc/images/JPEGImages' # 路径 filenames = os.listdir(path) # 获取文件名 print(filenames) # 'list' object has no attribute 'split' # filenames = filenames.split('.')[0] # 不会改变list中的值 for f in filenames: f = f.split('.')[0] # print(f) # 文件个数 print(len(filenames)) # 改变list中的值 for i in range(len(filenames)): filenames[i] = filenames[i].split('.')[0] print(filenames) path2='E:/a_final/voc/images/Annotations' filenames2 = os.listdir(path2) # 获取文件名 print(filenames2) print(len(filenames2)) for i in range(len(filenames2)): filenames2[i] = filenames2[i].split('.')[0] print(filenames2) for i in range(len(filenames2)): if filenames2[i] != filenames[i]: print(filenames2[i]) print(filenames[i]) break
获取文件夹中文件名
list去除后缀可行的方法
找出两个文件夹中第一处不同点
标签:Python,filenames2,list,len,filenames,split,print From: https://www.cnblogs.com/Lovzar/p/17361929.html