Can't get compression in Python zip script.

M.E.Farmer mefjr75 at hotmail.com
Mon May 2 16:17:26 EDT 2005


Steve Holden wrote:
> 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/
Ooops! Never tried it at the interpreter, I should have, sorry.
Glad to see you got my back Steve;)
I should have just pointed here:
http://docs.python.org/lib/module-zipfile.html

>>> a = zipfile.ZipFile('c:\tmp\z.zip', 'w', compression=1)
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "C:\Python22\Lib\zipfile.py", line 169, in __init__
    raise RuntimeError, "That compression method is not supported"
RuntimeError: That compression method is not supported
>>> a = zipfile.ZipFile('c:\tmp\z.zip', 'w', compression=8)

I saw compression=0 and assumed that 1 would mean true, but no!
zipfile.ZIP_DEFLATED = 8, defies logic, it is the only compression type
why not accept any non zero as compression.
Got any answers to the problems I outlined or have they been fixed yet
?
M.E.Farmer




More information about the Python-list mailing list