Boiler Plate Python: Difference between revisions

From Hive76 Wiki
Jump to navigationJump to search
(Created page with '= 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')…')
 
No edit summary
Line 1: Line 1:
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 and Unzipping files =
Zipping data into a file:
Zipping data into a file:

Revision as of 01:00, 1 September 2009

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