a.zip---
-- b.txt
-- c.txt
-- d.txt
Methods to process the zip files with Python,
I could expand the zip file to a temporary directory, then process each txt file one bye one
Here, I am more interested to know whether or not python provides such a way so that
I don’t have to manually expand the zip file and just simply treat the zip file as a specialized folder and process each txt accordingly.
The Python standard library helps you.
Doug Hellman writes very informative posts about selected modules: https://pymotw.com/3/zipfile/
To comment on Davids post: From Python 2.7 on the Zipfile object provides a context manager, so the recommended way would be:
The
closemethod will be called automatically because of the with statement. This is especially important if you write to the file.