Can't get compression in Python zip script.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • deejaay@swbell.net

    Can't get compression in Python zip script.

    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:
    [color=blue]
    >import zipfile
    >zip = zipfile.ZipFile ('<path/zipfilename.zip >', 'w')
    >zip.write('<pa th/filename.txt>')
    >zip.close()[/color]

    Any help would be gratly appreciated

    deej



  • M.E.Farmer

    #2
    Re: Can't get compression in Python zip script.

    zipfile.ZipFile .__init__(self, filename, mode='r', compression=0)
    Open the ZIP file with mode read "r", write "w" or append "a".
    [color=blue]
    >import zipfile
    >zip = zipfile.ZipFile ('<path/zipfilename.zip >', 'w', compression=1)
    >zip.write('<pa th/filename.txt>')
    >zip.close()[/color]

    Warning about zipfile module:
    In Python2.2 this is true, maybe 2.3 and 2.4 also have some problems.
    You cannot remove/delete an entry from a zipfile with Python but you
    can read and write it!
    To do it you will have to make a new zip file that contains all the
    files you want to keep and then overwrite the original.
    You can have mulitple files with the same name!
    Obviusly that can cause problems.
    This can be very confusing.
    hth,
    M.E.Farmer

    Comment

    Working...