📅 2013-Oct-03 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ python, zipfile ⬩ 📚 Archive
Reading the contents of files inside a zip file is easy with Python. We can use the zipfile module to achieve this.
Open the zip file using the ZipFile
constructor. Get the list of files inside it using infolist()
and open each of those files using open()
. After that you can read from it just like a normal file.
import zipfile
def read_zip_file(filepath):
= zipfile.ZipFile(filepath)
zfile for finfo in zfile.infolist():
= zfile.open(finfo)
ifile = ifile.readlines()
line_list print line_list
Tried with: Python 2.7.3