Search code examples
pythonlistzip

Extract from zip file to a list


I'm trying to extract a set of photos from a zip file using python and then saving those pictures to an image list to do some work on each.

I tried a lot, but nothing was useful to me.


Solution

  • Try this:

    import zipfile
    
    path = 'path_to_zip.zip'
    input_zip = zipfile.ZipFile(path)
    l = [input_zip.read(name) for name in input_zip.namelist()]
    

    To Display one of the images you can do:

    import io
    
    import matplotlib.pyplot as plt
    from PIL import Image
    
    image = Image.open(io.BytesIO(l[0]))
    plt.imshow(image)