1

我正在使用祝福(或祝福)来尝试在 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.

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

4

1 回答 1

0

终端高度是唯一的: [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
于 2019-08-08T14:55:36.287 回答