Fareen Khan
Fareen Khan

Reputation: 9

Exception has occurred: AttributeError '_csv.reader' object has no attribute 'shape'

I am getting the below error in Python3: Exception has occurred: AttributeError '_csv.reader' object has no attribute '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)

Upvotes: 0

Views: 1467

Answers (1)

Andrew F
Andrew F

Reputation: 2950

The csv.reader type does not have a .shape attribute. I usually do something like this

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

Upvotes: 2

Related Questions