Open a zip archive and iterate through its files with Python
Open a file compressed as .zip and iterate through its files line by line with Python.
import zipfile #Path to the zip file zipfilepath = 'path_to_zip_file' #Read in zip file zip = zipfile.ZipFile(zipfilepath) #Iterate through files in zip file for zipfilename in zip.filelist: #Read contents of the file filecontents = zip.read(zipfilename) #Break up contents into list and process for line in filecontents.replace('\r\n', '\n').split('\n'): print line
Leave a Reply