我试图逐行处理tab csv文件下面。它引发错误。无法追踪我错在哪里。
这是文件:
/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]
输出:
[root@localhost ~]# python 9.py
File "9.py", line 3
rown = csv.reader(f,delimiter='\t')
^
IndentationError: expected an indented block
答案 0 :(得分:3)
IndentationError
错误。推送with
语句
<强>实施例强>
import csv
with open('/tmp/fa.csv') as f:
rown = csv.reader(f,delimiter='\t')
for row in rown:
print row[1]
答案 1 :(得分:3)
您获得的错误是indentation
错误,而不是您的代码中的逻辑。
这是完整的工作代码: -
import csv
with open('/tmp/fa.csv') as f:
rown = csv.reader(f,delimiter='\t')
for row in rown:
print row