文件夹下图片全部重命名
import os
s = os.sep # s区分在linux或windows系统下的分割符"/"或""
root = "./train" # 文件路径
# root = "F:\theRoleOfCOde深度学习聊天模型重新开始success _2_ingdataRobot" # 文件路径
sname = os.listdir(root)
a = 0
for f in sname:
if ".png" in f:
os.rename("./train/" + str(f), "./train/" + str(a) + '.png')
a += 1
文件一行行处理
with open('./ksize.txt') as txt:
data = txt.readline()
while data:
temp = []
data = data.split(" ")
if len(data) < 2:
break
temp.append(int(data[1]))
temp.append(int(data[2]))
temp.append(int(data[3]))
temp.append(int(data[4]))
y.append(temp)
data = txt.readline()