Python-IndentationError:应为缩进块
我正在使用python脚本读取该文件,但它将一个错误显示为IndentationError。这是我的密码Python-IndentationError:应为缩进块,python,indentation,Python,Indentation,我正在使用python脚本读取该文件,但它将一个错误显示为IndentationError。这是我的密码 import subprocess f = subprocess.Popen(['tail','-F','filepath'],\ stdout=subprocess.PIPE,stderr=subprocess.PIPE) while True: line = f.stdout.readline() if line == "": else
import subprocess
f = subprocess.Popen(['tail','-F','filepath'],\
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
line = f.stdout.readline()
if line == "":
else:
print line
我得到的错误是
else:
^
IndentationError: expected an indented block
提前感谢。解决此问题的简单方法是使用:
if line != "":
print line
不需要
else
如果块中没有任何内容,则块中没有任何内容。如果您想避免If
阻塞,可以在其中使用pass
,或者更改If
条件。您可能还想更轻松地处理空行,也可以使用谷歌搜索并阅读PEP8。If line!=“”:打印行
,完全不需要
否则
。如果行为空,我不想打印任何内容。是否在if条件中编写了任何代码,并且如果希望跳过编写代码(例如,出于临时开发目的)pass
语句可以使用。