【问题标题】:Why does my python blessings print statement not print in the same spot?为什么我的python祝福打印语句不在同一个位置打印?
【发布时间】:2019-08-08 14:48:22
【问题描述】:

我正在使用祝福(或祝福)来尝试在 for 循环中的同一位置打印。但是,我发现这仅在我在终端底部上方打印 3 时才有效,但如果我在底部上方打印 1 或两行,它会为每次迭代打印一个新行...

对于 y=term.height-3:

from blessed import Terminal

term = Terminal()
print()
print()
for i in range(0,999999999):

    with term.location(y=term.height-2):

        print('Here is the bottom.')

这段代码打印了这个:

Here is the bottom.

每次迭代都会这样做。

但是,如果我将打印位置更改为

with term.location(y=term.height-1):

这样做

Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.
Here is the bottom.

等等等等..这是为什么?

【问题讨论】:

    标签: python blessed python-blessings


    【解决方案1】:

    终端高度是唯一的:[0,N] => N+1
    为简单起见,我们取 N = 3

    0 >
    1 >
    2 >
    3 >
    

    term.height = 4
    term.height - 1 = 3
    结果

    0 > hidden to keep height = 4 and because you wrote on line 4
    1 > 
    2 >
    3 > (3,1)
    4 > Bottom is here
    

    现在让我们再做一次,我们有这个

    1 > 
    2 >
    3 > (3,1)
    4 > Bottom is here
    
    In height results in
    
    [1] 0 > 
    [2] 1 >
    [3] 2 > (3,1)
    [4] 3 > Bottom is here
    

    然后在第 3 行打印

    [1] 0 > hidden to keep height = 4 and because you wrote on line 4
    [2] 1 >
    [3] 2 > (3,1)
    [4] 3 > (3,1)
    [5] 4 > Bottom is here
    

    【讨论】:

    • 我仍然很困惑为什么程序不只是在一个地方打印,而是将之前的打印语句向上推
    • 您在最后一行 3 和 4 上打印两行,因此您的终端从 1 向下滚动到 4,最后两行正常写入,然后您再次执行此操作并使用终端写入第 4 行和第 5 行在 2 到 5 之间,但 1 仍然写着你的文字。等等……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 2014-02-16
    • 2019-10-06
    • 1970-01-01
    • 2019-06-20
    • 1970-01-01
    • 2020-06-18
    相关资源
    最近更新 更多