unziping a file in python..

MRAB google at mrabarnett.plus.com
Mon Mar 2 08:52:08 EST 2009


Steven D'Aprano wrote:
> On Mon, 02 Mar 2009 01:00:54 -0500, David Lyon wrote:
> 
>> It might seem a simple question.. but how does one programmaticaly unzip
>> a file in python?
> 
> 
> A quick and dirty solution would be something like this:
> 
> zf = zipfile.ZipFile('Archive.zip')
> for name in zf.namelist():
>     open(name, 'w').write(zf.read(name))
> 
You might want to specify an output folder (and the data might be binary
too):

zf = zipfile.ZipFile('Archive.zip')
for name in zf.namelist():
     open(os.path.join(output_folder, name), 'wb').write(zf.read(name))




More information about the Python-list mailing list