En Wed, 04 Feb 2009 00:36:40 -0200, Brandon Taylor
<btaylordes...@gmail.com> escribió:
On Feb 3, 1:16 pm, Brandon Taylor <btaylordes...@gmail.com> wrote:
On Feb 3, 9:45 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
> En Tue, 03 Feb 2009 05:31:24 -0200, Brandon Taylor
> <btaylordes...@gmail.com> escribió:
> > 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)
Ok, the first thing I needed to do was add:
from __future__ import with_statement at the beginning of my file
That should not be necesary with your Python version (2.6.1 isn't it?)
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__'
Ouch, sorry, this new feature will appear in the not-yet-released 2.7
version...
Try this instead:
source = zip_file.open(zip_name + '/' + thumbnail_image)
try:
with open(os.path.join(thumbnail_path, thumbnail_image), 'wb') as target:
shutil.copyfileobj(source, target)
finally:
source.close()
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list