pythonfor-loopimage-processingimage-generation

Python:Generate a variable inside a for loop


I am trying to generate and save an image with a new name for each loop.Is this possible in python with a for loop?Or should I try a different approach?

For i in range(x,y)
 i=str(i)
 p= img(i).save(s+i+j,)
 i=int('i')
 i=i+1

Solution

  • from PIL import Image
    
    images = [...]
    
    # create some images 
    
    for i, image in enumerate(images):
        image.save('image_%03d.png' % i)