Prev: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters
Next: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters
From: Girish on 22 Jul 2010 02:35 Hello All, I am using Python 2.5. How do I extract all the files and directories in a zip file? Thanks in advance.. -Girish
From: Steven D'Aprano on 22 Jul 2010 03:21
On Wed, 21 Jul 2010 23:35:32 -0700, Girish wrote: > Hello All, > > I am using Python 2.5. How do I extract all the files and directories in > a zip file? import zipfile z = zipfile.ZipFile("test.zip", mode="r") for internal_filename in z.namelist(): contents = z.read(internal_filename) open(internal_filename, 'w').write(contents) z.close() Or upgrade to Python 2.6 and use the extractall method: http://docs.python.org/library/zipfile.html#zipfile.ZipFile.extractall -- Steven |