0

I am getting error while reading a csv file "example.csv", below is the code for the same :

import csv

with open('example.csv') as csvfile:
    readCsv=csv.reader(csvfile, delimiter=',')

for row in readCsv:
    print row

The error I am getting is :

AttributeError: 'module' object has no attribute 'reader'
ZdaR
  • 22,343
  • 7
  • 66
  • 87
Mukul
  • 351
  • 1
  • 7
  • 18
  • Please use code formatting and align the code. – nir0s Mar 13 '17 at 11:20
  • Can you post the entire traceback? It's probably because you have a `csv.py` file in your current directory. – nir0s Mar 13 '17 at 11:23
  • Strange. `csv` should have a `reader` attribute. Please `print(dir(csv))`. Perhaps you are importing from the wrong place. – Denziloe Mar 13 '17 at 11:25
  • 2
    This way you will get a `ValueError: I/O operation on closed file`. Indent the `for` loop and it should be just fine. Tested and worked for me. – Szabolcs Mar 13 '17 at 11:32
  • Thanks that solved my problem, that was because of that csv.py file @nir0s – Mukul Mar 14 '17 at 09:44

0 Answers0