Search code examples
pythonobject-detection

How to append all items in the list?


I need to write image_ids in a file which exist in mmdetection class . i tried to get the image_id by img_meta['ori_filename'] and implement this code to write all of the ids

        data1=[]
        data1.append(img_meta['ori_filename'])
        f=open('file.txt','w')
        for i in data1:  
             f.write(i)

but it write only one image . it couldn't append all the images i have


Solution

  • I assume you have a variable image_metas where all the images are stored.

    data1=[]
    for img_meta in image_metas:
        data1.append(img_meta['ori_filename'])
    f=open('file.txt','w')
    for i in data1:  
         f.write(i)