Adding to a zip file

Istvan Albert ialbert at mailblocks.com
Wed Jul 28 15:33:09 CEST 2004


Dennis Hotson wrote:

> On Wed, 28 Jul 2004 06:47:49 -0400, Peter Hansen wrote:
>
>>Look for the writestr() method of the ZipFile object.
> 
> 
> Ahhh... works a treat!

Check the compression rates within the zipfile. I had some
problems with the writestr method:

----

import zipfile, time

zfile = zipfile.ZipFile('test.zip', 'w', zipfile.ZIP_DEFLATED)
data  = 'whatever             ' * 100
zinfo = zipfile.ZipInfo('message.txt', time.localtime()[:6])
zfile.writestr(zinfo, data)
zfile.close

-----

On my windows system this generates a test.zip file that
contains the message.txt entry but without compression!
(0% compression ratio).

I wasn't motivated enough to find out what exactly is happening
because the file based methods worked properly and turned out
to be a better solution for my problem.

Istvan.




More information about the Python-list mailing list