我编写这个简短的脚本是为了在csv中自动打印出包含“1 | 1”的字符串。但是,当我在if status=='1 | 1'中添加时,出现了缩进错误。我是新手,有人能帮忙吗
inputfile = csv.reader(open('varStatus.csv','r'))
outputfile = open('errorlist.txt','w')
i=0
for row in inputfile:
if (i > 5):
name = row[1]
status = row[0]
if (status == '1|1'):
print >>outputfile, name, status
i+=1
我在UNIX上使用python
您需要正确缩进代码。Python解释空白,所以必须缩进每个if语句
您好,这是一个缩进错误,因为在IF语句之后,您没有给出缩进块,因为IF条件没有执行任何内容
我认为这应该行得通。此外,如果您是Python新手,还没有掌握缩进的窍门,请查看https://www.w3schools.com/python/gloss_python_indentation.asp#:~:text=%E2%9D%AE%20Python%20Glossary-,Python%20Indentation,indicate%20a%20block%20of%20code
相关问题 更多 >
编程相关推荐