#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Angry HELP: how to open a .csv file in Python?


    Hello,

    This is probably something really simple, but I am not particularly familiar with Python so I thought I would ask as I know that python has an excel module.

    How can I insert a .csv file into Python 3.2.3?

    Does anyone have a code for this?

    Any help much appreciated..

    Thanks,
    Mr_Shed
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Code:
    >>> import csv
    >>> with open('doremi.csv') as csvfile:
    ...     doremi_reader = csv.reader(csvfile, delimiter=',')
    ...     for row in doremi_reader:
    ...             print("-".join(row))
    ... 
    do-re-me-fa-so-la-ti
    http://www.catb.org/esr/faqs/smart-questions.html#code
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    2
    For many applications, the csv module is a bit of overkill. You can:
    Code:
    f=open("doremi.csv")
    recordlst=[]
    for record in f:
        recordlst.append(record.strip('\n').split(','))

IMN logo majestic logo threadwatch logo seochat tools logo