Re: Read number of CSV files

Discussion in 'Python' started by Peter Otten, Nov 8, 2012.

  1. Peter Otten

    Peter Otten Guest

    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)
     
    Peter Otten, Nov 8, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    0
    Views:
    692
    Michal Mikolajczyk
    Feb 13, 2004
  2. jliu66
    Replies:
    0
    Views:
    560
    jliu66
    Oct 19, 2007
  3. Li Chen
    Replies:
    18
    Views:
    717
    Azmi Farih
    Mar 23, 2010
  4. Sacha Rook

    csv read clean up and write out to csv

    Sacha Rook, Nov 2, 2012, in forum: Python
    Replies:
    2
    Views:
    244
    Hans Mulder
    Nov 2, 2012
  5. Peter Otten

    Re: Read number of CSV files

    Peter Otten, Nov 12, 2012, in forum: Python
    Replies:
    0
    Views:
    215
    Peter Otten
    Nov 12, 2012
Loading...

Share This Page