简体   繁体   English

为什么我的python祝福打印语句未在同一位置打印?

[英]Why does my python blessings print statement not print in the same spot?

I am using blessings (or blessed) to try to print in the same spot in a for-loop. 我正在使用祝福(或祝福)来尝试在for循环中的同一位置进行打印。 However, I find that this only works if I print 3 above the bottom of the terminal, but if I print 1 or two lines above the bottom it prints a new line for each iteration... 但是,我发现只有在终端底部上方打印3时才有效,但是如果在底部上方打印1或两行,则每次迭代都会打印新的一行...

For y=term.height-3: 对于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.')

This code prints this: 这段代码显示:

Here is the bottom.

It does that for every iteration. 每次迭代都会这样做。

BUT, if I change the print location to 但是,如果我将打印位置更改为

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

It does this 它做到了

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.

and so on and so on.. why is this? 等等等等..为什么呢?

Height of terminal is exclusive: [0,N] => N+1 终端高度不包括在内:[0,N] => N + 1
Let's take N = 3 for simplicity 为了简单起见,我们取N = 3

0 >
1 >
2 >
3 >

term.height = 4 term.height = 4
term.height - 1 = 3 term.height-1 = 3
results in 结果是

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

Now let's do it again, we have this 现在让我们再做一次

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

And you print at line 3 然后在第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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM