I made a little helper function:
import zipfile
def main(archive_list=[],zfilename='default.zip'):
print zfilename
zout = zipfile.ZipFile(zfilename, "w")
for fname in archive_list:
print "writing: ", fname
zout.write(fname)
zout.close()
if __name__ == '__main__':
main()
The problem is that all my files are NOT being COMPRESSED! The files are the same size and, effectively, just the extension is being change to ".zip" (from ".xls" in this case).
I'm running python 2.5 on winXP sp2.
This is because
ZipFile
requires you to specify the compression method. If you don't specify it, it assumes the compression method to bezipfile.ZIP_STORED
, which only stores the files without compressing them. You need to specify the method to bezipfile.ZIP_DEFLATED
. You will need to have thezlib
module installed for this (it is usually installed by default).There is a really easy way to compress
zip
format,Use in
shutil.make_archive
library.For example:
Can see more extensive documentation at: Here