Simple script to make .png thumbnails from .zip archive...
hdante at gmail.com
hdante at gmail.com
Tue Jun 20 04:59:26 EDT 2006
K P S wrote:
> Thanks everyone.
> routines to list all the files in a zip archive, but I don't see any to
> list only the first, or only the second, etc. It doesn't look like
If you can list all the files, then you can list only the first. :-)
Don't worry about python internal allocation procedures. It will try to
make things in an efficient way. Just make sure your code looks cool.
;-)
>
> zip=zipfile.ZipFile("text.zip",mode="r")
> picture=zip.read(zip.namelist(0))
That's because you're using the wrong syntax. -> zip.namelist()[0]
However, I bet that your first file in the zip is not a jpeg file. Do
this, instead:
zip = zipfile.ZipFile('text.zip')
jpeglist = [x for x in zip.namelist() if '.jp' in x]
try:
picture = zip.read(jpeglist[0])
except IndexError:
print 'No jpeg found'
More information about the Python-list
mailing list