python - 为什么我的python祝福打印语句不在同一个位置打印?
问题描述
我正在使用祝福(或祝福)来尝试在 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.
等等等等..这是为什么?
解决方案
终端高度是唯一的: [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
推荐阅读
- shiny - 如何在 R 闪亮的应用程序中操作数据框
- vue.js - 在Vue中将数据从子元素返回到父元素
- javascript - 如何使用提交输入按钮作为当前选项卡中另一个网页的链接?
- firebase - 要链接到电子邮件的 Firebase 匿名用户
- reactjs - 如何确保在 react-redux 中调用 componentDidMount() 之前返回更新的状态?
- php - 如何请求获取价值?
- java - 在 swing 中为 JTable 设置默认排序列
- javascript - 如何在 es6 中运行 nodejs child_process?
- javascript - 从 Javascript (nodeJS) 到 dart (Flutter) 以及从 dart 到 Javascript 的加密和解密
- python - Python 日志记录模块平台差异:OSX 与 Linux