Boiler Plate Python

From Hive76 Wiki
Revision as of 01:00, 1 September 2009 by 151.201.147.129 (talk)
Jump to navigationJump to search

Boilerplace Python is a project of FarMcKon involving a few Hive76 members. The goal is to put out a small python tool in 20-50 lines each week.

Zipping and Unzipping files

Zipping data into a file:

import zipfile
zipHandle = zipfile.ZipFile('archive.zip','w',zipfile.ZIP_DEFLATED
zipHandle.write('file_to_add.py')
zipHandle.close()
del zipHandle

Listing what's in a file:

import zipfile
zipHandle = zipfile.ZipFile('archive.zip','r')
filesInZip =  zipHandle.namelist():
for filename in filesInZip:
    print filename
zipHandle.close()
del zipHandle