unziping a file in python..
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Mar 2 11:18:10 EST 2009
En Mon, 02 Mar 2009 13:09:05 -0200, Luis Zarrabeitia <kyrie at uh.cu>
escribió:
> Quoting MRAB <google at mrabarnett.plus.com>:
>> 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').write(zf.read(name))
>>
>
> Question here... wouldn't you also need to create all the intermediate
> folders
> from "output_folder" to "output_folder/name" (assuming that 'name' has
> several
> path parts in it)? Is there any elegant way to do it?
Perhaps it would be easier to grab a copy of the 2.6 sources. extract()
and extractall() are not so complex, but "the devil is in the details"
> (is there any way to make os.mkdir behave like mkdir -p?)
if not os.path.isdir(d):
os.makedirs(d)
--
Gabriel Genellina
More information about the Python-list
mailing list