-7

我的文件 abc.csv 包含:

a,b,c,d,e
f,g,h,i,j

我的代码如下;for 循环没有给我想要的输出,即 ch

for line1 in open('abc.csv', 'r') :
    result = line1.split(",")[2]
    print result    

我的代码有什么问题?

4

1 回答 1

-1

实际上,我验证了您的代码可以正常工作。但无论如何,您应该更喜欢csv解析 CSV 文件的模块:

import csv

with open('abc.csv', 'rb') as f:  # note the 'b' flag--this is needed with CSV
    for row in csv.reader(f, delimiter=','):
        print row[2]
于 2013-09-28T11:25:22.860 回答