小编Shi*_*pro的帖子

如何在python中打印下一行

我试图在比赛后打印接下来的 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)

我如何获得我想要的输出,请帮忙

python file-io file filestream python-3.x

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

file ×1

file-io ×1

filestream ×1

python ×1

python-3.x ×1