-1

Im Trying to Process below tab csv file line by line .It raising error.Unable to trace where im wrong.

Here is the file :

/tmp/fa.csv

1       Close
6       Close
72      Close
99      Close
8       Close
4       Close
3       Close
103     Close
106     Close
107     Close
105     Close
220     Open

9.py

import csv
with open('/tmp/fa.csv') as f:
rown = csv.reader(f,delimiter='\t')
for row in rown:
print row[1]

Output:

[root@localhost ~]# python 9.py
  File "9.py", line 3
    rown = csv.reader(f,delimiter='\t')
       ^
IndentationError: expected an indented block
Saikumar A
  • 35
  • 3
  • Check your indentation... Python I far less permissive than C on indent ! – Amperclock Mar 20 '18 at 09:51
  • provide and indentation before `print` statement as the error says – quest Mar 20 '18 at 09:52
  • Possible duplicate of [I'm getting an IndentationError. How do I fix it?](https://stackoverflow.com/questions/45621722/im-getting-an-indentationerror-how-do-i-fix-it) – khelwood Mar 20 '18 at 09:53
  • The error message literally tells you where the error is and what it is, and infers what you need to do :( – Antry Mar 20 '18 at 10:03

2 Answers2

3

IndentationError error. Push the content inside the with statement

Ex:

import csv
with open('/tmp/fa.csv') as f:
    rown = csv.reader(f,delimiter='\t')
    for row in rown:
        print row[1]
Rakesh
  • 81,458
  • 17
  • 76
  • 113
3

The Error you're getting is indentation error, not exactly of your logic in the code.

Here is complete working code:-

import csv
with open('/tmp/fa.csv') as f:
    rown = csv.reader(f,delimiter='\t')
    for row in rown:
        print row
the.salman.a
  • 945
  • 8
  • 29