发生异常:AttributeError'_csv.reader'对象没有属性'shape'

时间:2018-12-03 15:01:49

标签: python-3.x

我在Python3中遇到以下错误: 发生异常:AttributeError '_csv.reader'对象没有属性'shape'

import requests

from contextlib import closing

import csv

url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv'

with closing(requests.get(url, stream=True)) as r:

    f = (line.decode('utf-8') for line in r.iter_lines())
    a = csv.reader(f, delimiter=',', quotechar='"')
    for row in a:
        print(row)

print(a.shape)

1 个答案:

答案 0 :(得分:2)

csv.reader类型没有.shape属性。我通常会做这样的事情

a = csv.reader(f, ...)
rows = list(a)
for row in rows:
    # ...
print(len(rows))