Creating ZIP files

GIS often requires the use of large files that will be compressed into a .zip format for ease of sharing. Python includes a module that you can use to decompress and compress files in this format.

Getting ready

ZIP is a common compression and archive format and is implemented in Python through the zipfile module. The ZipFile class can be used to create, read, and write .zip files. To create a new .zip file, simply provide the filename along with a mode as w, which indicates that you want to write data to the file. In the following code example, we are creating a .zip file called datafile.zip. The second parameter, w, indicates that a new file will be created. A new file will be created or an existing file with the same name will ...

Get Programming ArcGIS with Python Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.