Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Read number of CSV files

Reply
Thread Tools

Re: Read number of CSV files

 
 
Peter Otten
Guest
Posts: n/a
 
      11-08-2012
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)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Read number of CSV files Peter Otten Python 0 11-12-2012 05:50 PM
csv read clean up and write out to csv Sacha Rook Python 2 11-02-2012 07:51 PM
read CSV file using csv library Li Chen Ruby 18 03-23-2010 12:44 AM
read and write csv file using csv module jliu66 Python 0 10-19-2007 03:12 PM
csv writerow creates double spaced excel csv files Michal Mikolajczyk Python 0 02-13-2004 08:38 PM



Advertisments