Python 打开文件 cvs reader 没有属性

Python open file cvs reader has no attribute

这应该打开一个制表符分隔的文件并打印第一行,然后将它们相加。该列只是数字。我有一个错误,也不确定之后如何将它们相加。

with open(filePath + fileName, 'rt')  as inputfile:
    next(inputfile)
    dataArray = csv.reader(inputfile, delimiter='\t')
    for row in inputfile:
        print dataArray.split('\t',1)

这是错误:

  File "./Medicalsys", line 38, in <module>
    print dataArray.split('\t',1)
AttributeError: '_csv.reader' object has no attribute 'split'

您需要将 dataArray 迭代为:

for row in dataArray:
    print(row[0])  # already split by tab by csv.reader(inputfile, delimiter='\t')