Search code examples
pythonsubprocess

Python script error :Unable to read csv file


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

Solution

  • 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]