Tuesday, September 26, 2006

Some very usefull python: Zipping a file

zip = zipfile.ZipFile('/afile.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir('/adirectory/', zip)
zip.close()

I couldn't get this to work unless I specified zipfile.ZIP_DEFLATED of course after reading I found out the default is zipfile.ZIP_STORED. If you don't specify ZIP_DEFLATED it creates a zip file that has 0% compression (basically just stores it) go figure :-)

Another thing I kept banging my head against was how to hide a dos popup window from a py2exe created file. A combination of
os.popen("xcopy /Y /F " + ServerPath + " c:\\").read()

PLUS in the setup file for py2exe change setup(console=['whatever.pyw']) to setup(windows=['whatever.pyw'])

Cool stuff this python

No comments: