Extracting file from zip archive in Python 2.6.1

Brandon Taylor btaylordesign at gmail.com
Tue Feb 3 22:56:32 EST 2009


On Feb 3, 9:15 pm, rdmur... at bitdance.com wrote:
> Quoth Brandon Taylor <btaylordes... at gmail.com>:
>
>
>
> > Ok, the first thing I needed to do was add:
>
> > from __future__ import with_statement at the beginning of my file
>
> > but:
>
> > 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)
>
> > Returns an error on the first line:
>
> > ZipExtFile instance has no attribute '__exit__'
>
> > Googling this error message is turning up nothing, and there's no
> > mention of the exception in the docs. Any thoughts?
>
> Yeah, that means the ZipExtFile object hasn't been extended to
> handle the context management protocol.  It would be pretty
> simple to roll your own for it.  Take a look at the contextlib
> module.
>
> --RDM

Cool. Thanks for the pointers. In the meantime, I just used extract
and os.rename to move the files where I need them, but I'll see if I
can save that extra step if possible.



More information about the Python-list mailing list