Can't get compression in Python zip script.

Steve Holden steve at holdenweb.com
Mon May 2 10:51:00 EDT 2005


deejaay at swbell.net wrote:
> Hello,
> I following an example on how to zip files from the www.devshed.com 
> site.
> I can create a zip package, however I am not getting any compression.
> 120M file stays 120M within the zip package.
> I need to know how to set or activate the compression values.
> here is the code I'm using:
> 
> 
>>import zipfile
>>zip = zipfile.ZipFile('<path/zipfilename.zip>', 'w')
>>zip.write('<path/filename.txt>')
>>zip.close()
> 
> 
> Any help would be gratly appreciated
> 
It's not that difficult. The zipfile module uses null compression by 
deafult, so you need to change the second line to read

zip = zipfile.ZipFile('<path/zipfilename.zip>', 'w', zipfile.ZIP_DEFLATED)

That will create a comrpessed zip file.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list