Unzip File un Python 5.5
Steven D'Aprano
steve-REMOVE-THIS at cybersource.com.au
Thu Jul 22 03:21:53 EDT 2010
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
More information about the Python-list
mailing list