unziping a file in python..

2009-03-01 Thread David Lyon
It might seem a simple question.. but how does one programmaticaly unzip a file in python? In version 2.6 and above.. the zipfile module has an extractall method. But it isn't available in 2.5 or below. Any cross version, cross-platform answers welcome. Any answers specific to win32 also welcom

Re: unziping a file in python..

2009-03-01 Thread Steven D'Aprano
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(

Re: unziping a file in python..

2009-03-02 Thread MRAB
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():

Re: unziping a file in python..

2009-03-02 Thread Luis Zarrabeitia
Quoting MRAB : > Steven D'Aprano wrote: > > 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 bin

Re: unziping a file in python..

2009-03-02 Thread MRAB
Luis Zarrabeitia wrote: Quoting MRAB : Steven D'Aprano wrote: 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 bin

Re: unziping a file in python..

2009-03-02 Thread Gabriel Genellina
En Mon, 02 Mar 2009 13:09:05 -0200, Luis Zarrabeitia escribió: Quoting MRAB : Steven D'Aprano wrote: > 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

Re: unziping a file in python..

2009-03-02 Thread David Lyon
On Mon, 02 Mar 2009 16:13:39 +, MRAB wrote: > zf = zipfile.ZipFile('Archive.zip') > for name in zf.namelist(): > new_path = os.path.join(output_folder, name) > data = zf.read(name) > try: > open(new_path, 'wb').write(data) > except IOError: > # Create i