gpt4 book ai didi

linux - 在 stdout 中打印从底部开始的第 3 行

转载 作者:太空宇宙 更新时间:2023-11-04 10:39:21 25 4
gpt4 key购买 nike

目前我正在运行这个

while p.poll() is None:
output = p.stdout.readline()
print output,

发生的事情是所有的行都被打印出来了。我正在寻找的是打印,通常是从底部开始的 第 3 行,其中包含有关命令是否正确执行的数据。

此外,还有一种方法可以让底部的状态栏使用 Tkinter Label 实时更新

最佳答案

解决方案,感谢@TadhgMcDonald-Jensen 的提示

在终端 shell 窗口中仅打印倒数第三行(索引 -3)

import Tkinter as *
import subprocess

out = [] # Create empty list
for line in iter(p.stdout.readline, ''):
out.append(line.rstrip('\n')) # append list
print out[-3] # print item in the list, in this case -3

或者显示在 tkinter 标签中

import Tkinter as *
import subprocess

out = [] # Create empty list
for line in iter(p.stdout.readline, ''):
out.append(line.rstrip('\n')) # append list
window = Tk()
Label(window, text=out[-3]).grid(sticky=W)

关于linux - 在 stdout 中打印从底部开始的第 3 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35874340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com