Working with ZIP Files in Python

2011/02/13

Tagged with: python

Note: This is the fourth post in the Bulk Tag Generation in Python series.

Working with ZIP files in Python is pretty easy. Just import the zipfile module, and you're pretty much done.

Here's some sample code:

import zipfile
myzip = zipfile.ZipFile("something.zip")
file_list = myzip.namelist()
file_data = [myzip.read(filename) for filename in file_list]

Just import the module, open the zip, get a file list out, and then you have a list containing all the data in each of the files. Pretty nifty, isn't it?

- Hasnain

PS: Hopefully the time difference between blog posts will go down soon.

comments powered by Disqus