python notes-1

(1) Write the image path to the small chestnut in txt:

# -*- coding: utf-8 -*-

import  glob
a=glob.glob('layers/*.jpg')

for i in range(len(a)):
a[i]=a[i].split('/')[-1]

f=file('list.txt','w')
for i in a:
    f.write(i+'\n')

f.close()

(2) Extract the label chestnut in the image path:

# -*- coding: utf-8 -*-

with open("/home/sll2/Desktop/train_s.txt","r")as f:
    lines=f.readlines()
with open("/home/sll2/Desktop/train_s.txt","w+")as f_w:
    for line in lines:
        label=line.split('/')[-3]
        #label=int(label)
        line=line.strip('\n')
        f_w.write(line+' '+label+'\n')

f.close()
f_w.close()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325688103&siteId=291194637