python %s在字符串中的正确使用

it2024-01-31  69

借鉴:python遍历整个文件夹中的所有.txt文件并将绝对路径保存在指定的txt文档中的 >>> 程序

import os sets=['train','test','val'] for image_set in sets: image_path=os.path.join('..\\Visdrone2019\\JPEGImages\\%s') %(image_set) txt=open("..\\coco\\"+"%s"%(image_set)+".txt",'w') for (dirpath,dirnames,filenames) in os.walk(image_path): for filename in filenames: if os.path.splitext(filename)[1]=='.jpg': txt.write('..\\Visdrone2019\\JPEGImages\\%s\\'+filename+'\n')

记录一下%s的正确位置

最新回复(0)