extract zip file python

48

how to unzip files using zipfile module python -

import zipfile
with zipfile.ZipFile("file.zip","r") as zip_ref:
    zip_ref.extractall("targetdir")

python unzip a zip -

# app.py

from zipfile import ZipFile

with ZipFile('Mail3.zip', 'r') as zipObj:
   # Extract all the contents of zip file in different directory
   zipObj.extractall('temp')
   print('File is unzipped in temp folder')

python extract zip file -

from zipfile import ZipFile
import zipfile

myzip = ZipFile('test.zip') 
myzip.extract(member='Roughwork/pretify.html') 

extract zip file in python zipfile -

from zipfile import ZipFile
import zipfile

with ZipFile('test.zip') as myzip:
    with myzip.open('Roughwork/textfile.text') as myfile:
        print(myfile.readlines())Copy Code

how to extract zip file using python -

ZipFile.extractall(path=None, members=None, pwd=None)

Comments

Submit
0 Comments