Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32936 > unrolled thread

Re: Read number of CSV files

Started byPeter Otten <__peter__@web.de>
First post2012-11-08 09:44 +0100
Last post2012-11-08 09:44 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Read number of CSV files Peter Otten <__peter__@web.de> - 2012-11-08 09:44 +0100

#32936 — Re: Read number of CSV files

FromPeter Otten <__peter__@web.de>
Date2012-11-08 09:44 +0100
SubjectRe: Read number of CSV files
Message-ID<mailman.3426.1352364301.27098.python-list@python.org>
Smaran Harihar wrote:

> I am able to read through a CSV File and fetch the data inside the CSV
> file but I have a really big list of CSV files and I wish to do the same
> particular code in all the CSV files.
> 
> Is there some way that I can loops through all these files, which are in a
> single folder, and get my code to read the files?

import glob
import csv

def process(filename):
    with open(filename, "rb") as f:
        rows = csv.reader(f)
        for row in rows:
            ... # whatever you want

for filename in glob.glob("/path/to/*.csv"):
    process(filename)

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web