Tutorial by Examples

To start, import the zipfile module, and set the filename. import zipfile filename = 'zipfile.zip' Working with zip archives is very similar to working with files, you create the object by opening the zipfile, which lets you work on it before closing the file up again. zip = zipfile.ZipFile(fi...
There are a few ways to inspect the contents of a zipfile. You can use the printdir to just get a variety of information sent to stdout with zipfile.ZipFile(filename) as zip: zip.printdir() # Out: # File Name Modified Size ...
Extract all file contents of a zip file import zipfile with zipfile.ZipFile('zipfile.zip','r') as zfile: zfile.extractall('path') If you want extract single files use extract method, it takes name list and path as input parameter import zipfile f=open('zipfile.zip','rb') zfile=zipfile.Z...
To create new archive open zipfile with write mode. import zipfile new_arch=zipfile.ZipFile("filename.zip",mode="w") To add files to this archive use write() method. new_arch.write('filename.txt','filename_in_archive.txt') #first parameter is filename and second parameter i...

Page 1 of 1