我似乎无法跳过空线 -的Python - 跳过空行和打印3行的匹配后
import re
with open('list.txt', 'r+') as f:
line = f.readline()
while(line):
if line != ['']:
if " win" in line:
print(f.readline(),end="")
# 2nd line
print(f.readline(),end="")
# 3rd line
print(f.readline(),end="")
line = f.readline()
LIST.TXT
You tell yourself...
That should have been my big win.
It's a kick in the gut.
Knowing in your heart the reason.
While you're stuck on the outside.
Grinning.
它打印中包含instead- 线在空行后出现。
It's a kick in the gut. Knowing in your heart the reason.
你到底想干什么?比赛结束后打印3条非空线? – TemporalWolf
是的,比赛结束后有3条非空线 – Arif
一条线可以显示为空,但是每条线都以换行符结束。在检查内容之前,你需要去掉('str.rstrip()'应该足够)你的行... – zwer