get file list of files contained in a zip file

前端 未结 3 1629
慢半拍i
慢半拍i 2020-12-13 07:57

I have a zip archive: my_zip.zip. Inside it is one txt file, the name of which I do not know. I was taking a look at Python\'s zipfile

3条回答
  •  清歌不尽
    2020-12-13 08:56

    import zipfile
    
    zip = zipfile.ZipFile('filename.zip')
    
    # available files in the container
    print (zip.namelist())
    
    
    # extract a specific file from zip 
    f = zip.open("file_inside_zip.txt")
    content = f.read()
    # save the extraced file 
    f = open('file_inside_zip.extracted.txt', 'wb')
    f.write(content)
    f.close()
    

提交回复
热议问题