[Python] Read all files in .zip archive in python

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to read all files in a .zip archive named data1.zip using the glob() method.

    import glob
    from zipfile import ZipFile

    archive = ZipFile('data1.zip','r')
    files = archive.read(glob.glob('*.jpg'))


    Error Message:

    TypeError: unhashable type: 'list'


    The solution to the problem I'm using is:

    files = [archive.read(str(i+1)+'.jpg') for i in range(100)]


    This is bad because I'm assuming my files are named 1.jpg, 2.jpg, etc.

    Is there a better way using python best practices to do this? Doesn't need to be necessarily using glob()

    Continue reading...

Compartilhe esta Página