import os filePath = 'img' path2 = r'/config/FHY_gps.txt' path3 = r'/config/FHY_gps_new.txt' name = os.listdir(filePath) name.sort(key=lambda x:float(x[:-4])) file=open(path2) file2 = open(path3,'w+') i=0 for line in file.readlines(): curline=line.split(" ") rel_name = name[i].split('.') reline = rel_name[0] +"." + rel_name[1] + " " + curline[1] + " " + curline[2] + " " + curline[3] print(rel_name[0],curline[1]) print(reline+"\n") file2.write(reline) i=i+1 #file2 = open(path2,'w+') #for x in name: # #rel_name = x.split('.') # line = x[:-4] + " " + "rgb/" + x + "\n" # file2.write(line)
标签:file2,读取,curline,python,rel,line,txt,name From: https://www.cnblogs.com/gooutlook/p/16898992.html