Extracting file from zip archive in Python 2.6.1

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Feb 3 10:45:27 EST 2009


En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor  
<btaylordesign at gmail.com> escribió:

> I'm having an issue specifying the path for extracting files from
> a .zip archive. In my method, I have:
>
> zip_file.extract(zip_name + '/' + thumbnail_image, thumbnail_path)
>
> What is happening is that the extract method is creating a folder with
> the name of 'zip_name' and extracting the files to it. Example:

extract will create all directories in member name. Use open instead:

with zip_file.open(zip_name + '/' + thumbnail_image) as source:
   with open(os.path.join(thumbnail_path, thumbnail_image), "wb") as target:
     shutil.copyfileobj(source, target)

(untested)

-- 
Gabriel Genellina




More information about the Python-list mailing list