Thursday, July 15, 2010

creating zip file in python and compression

I am a java programmerr but sometimes program in python.I must say python is very easy to do stuff that requires very verbose coding in java. To create a zip file in python all you need to do is :

import zipfile
restoreZip = zipfile.ZipFile("", "w")
restoreZip.write(physicalPathOfFile, logicalPathOfFileInZip)

Now python doesnt compress by default so you need to add compression mode while opening zip file

restoreZip = zipfile.ZipFile("", "w", zipfile.ZIP_DEFLATED)

solved the issue

1 comment:

  1. thanks for the info. (u were quoted in StackOverFlow)
    A google wanderer