Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-IndentationError:应为缩进块_Python_Indentation - Fatal编程技术网

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

我正在使用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:   

        print line
我得到的错误是

else:   
       ^
IndentationError: expected an indented block

提前感谢。

解决此问题的简单方法是使用:

if line != "":   

    print line

不需要
else

如果
块中没有任何内容,则
块中没有任何内容。如果您想避免
If
阻塞,可以在其中使用
pass
,或者更改
If
条件。您可能还想更轻松地处理空行,也可以使用谷歌搜索并阅读PEP8。
If line!=“”:打印行
,完全不需要
否则
。如果行为空,我不想打印任何内容。是否在if条件中编写了任何代码,并且如果希望跳过编写代码(例如,出于临时开发目的)
pass
语句可以使用。