我试图在比赛后打印接下来的 3 行
例如输入是:
Testing
Result
test1 : 12345
test2 : 23453
test3 : 2345454
Run Code Online (Sandbox Code Playgroud)
所以我试图在文件中搜索“结果”字符串并从中打印下 3 行:
输出将是:-
test1 : 12345
test2 : 23453
test3 : 2345454
Run Code Online (Sandbox Code Playgroud)
我的代码是:
with open(filename, 'r+') as f:
for line in f:
print line
if "Benchmark Results" in f:
print f
print next(f)
Run Code Online (Sandbox Code Playgroud)
它只给我输出:
testing
Run Code Online (Sandbox Code Playgroud)
我如何获得我想要的输出,请帮忙