[CentralOH] Improving Zipfile Code

Nick Albright nick.albright at gmail.com
Mon Oct 22 21:18:47 CEST 2012


Oo!  fnmatch, didn't know about that one! Slick!

On Mon, Oct 22, 2012 at 11:57 AM, <jep200404 at columbus.rr.com> wrote:

> 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.
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20121022/7c93c446/attachment.html>


More information about the CentralOH mailing list