简体   繁体   中英

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

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]

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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM