开发者

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 scr开发者_JAVA技巧ipt is not reading the column header.


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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜