Siddharth Ravindran
Siddharth Ravindran

Reputation: 47

How to read a header from a CSV file using python

i tried the following script as per ur suggestion and i get an error import csv

def main():
    col_name = "\\xyz-abc\Procz(abcd)\Digital"
    with open('C:\\read.csv', 'rb') as inf:
        reader = csv.reader(inf)
        col_index = next(reader).index(col_name)
        highest = max(rec[col_index] for rec in reader)
        print "test"
main()     

I get an error ValueError: '\\\\xyz-abc\Procz(abcd)\Digital' is not in list please help me.. I think the script is not reading the column header.

Upvotes: 0

Views: 1128

Answers (1)

Rob Cowie
Rob Cowie

Reputation: 22619

Give this a go. Prevent the back-slashes being interpreted as escape characters by using a raw string

col_name = r"\\xyz-abc\Procz(abcd)\Digital"

Upvotes: 2

Related Questions