-1
我正在使用python腳本來讀取文件,但它顯示爲IndentationError錯誤。這裏是我的代碼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'塊沒有任何東西。如果你想避免'if'塊,可以使用'pass'或者改變'if'的條件 – kuro
你可能還想用空行和谷歌來閱讀,也可以閱讀PEP8。 – pvg
'if line!=「」:print line',根本不需要'else' –