All Tools Bookmark

Share

http://www.online-toolz.com/howto/python-read-csv-file.php

Facebook Share Twitter Share

Python Read CSV File Python

The code snippets below shows how to Read a CSV File in Python




        import csv

        path = 'c:\\temp\\'

        file=open( path +"xyz.CSV", "r")

        reader = csv.reader(file)

        for line in reader:
            t=line[1],line[2]
            print(t)

        
source


        import sys

        csvFile = open('pathOfCSV','r')
        for line in csvFile.readlines():
            l = line.split()
            if len(l) > 1: # informations in columns A and B
                sys.stdout.write('ColumnA : %s, ColumnB : %s\n'%(l[0],l[1]))
        csvFile.close()

        
source