Extracting file from zip archive in Python 2.6.1
rdmurray at bitdance.com
rdmurray at bitdance.com
Tue Feb 3 22:15:18 EST 2009
Quoth Brandon Taylor <btaylordesign 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
More information about the Python-list
mailing list