Boiler Plate Python

From Hive76 Wiki
Revision as of 23:00, 8 September 2009 by FarMcKon (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, 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. You can get to most of the examples at Far's Website

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