For_loops hurt my brain.

bsagert at gmail.com bsagert at gmail.com
Wed Jul 16 13:42:18 EDT 2008


This script uses a simple for loop to zip some files. However I am
repeating code that cries out for a nested loop. My two lists of
files_to_be_zipped (spare and seekfacts) are of uneven length so I
can't seem to decipher the "for_logic". I would appreciate any help.
Thanks, Bill

import zipfile
import os

zips = [
'c:/spare.zip',
'c:/seekfacts.zip'
]
spare = [
'c:/spare/huge.fm3',
'c:/spare/huge.wk3'
]
seekfacts = [
'c:/seekfacts/bookmark.html',
'c:/seekfacts/index.htm',
'c:/seekfacts/seek.css',
'c:/seekfacts/seek.js'
]

zFile = zipfile.ZipFile(zips[0], 'w')
for files in spare:
	zFile.write(files, os.path.basename(files), zipfile.ZIP_DEFLATED)
zFile.close()

zFile = zipfile.ZipFile(zips[1], 'w')
for files in seekfacts:
	zFile.write(files, os.path.basename(files), zipfile.ZIP_DEFLATED)
zFile.close()




More information about the Python-list mailing list