[CentralOH] Improving Zipfile Code

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Mon Oct 22 17:57:48 CEST 2012


On Mon, 22 Oct 2012 09:27:13 -0400, Eric Floehr <eric at intellovations.com> wrote:

> With those revisions, here is the updated code:
> 
> import csv
> import fnmatch
> from zipfile import ZipFile
> 
> def foo(zipfilename):
>     z = ZipFile(zipfilename)
>     for filename in fnmatch.filter(z.namelist(), '*.xyz'):
>         csvfile = z.open(filename, 'rU')  # Open with universal newline support
>         csvreader = csv.DictReader(csvfile)
>         for row in csvreader:
>             print 'line_number:', csvreader.line_num, 'row:', row

Thanks! That has _several_ nifty things, improving my code much. 
Python libraries continue to impress. 



More information about the CentralOH mailing list