Can't get compression in Python zip script.

D

deejaay

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

deej
 
M

M.E.Farmer

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top