我知道要在命令行上更新类似进度条的东西,可以使用'\ r'。有没有办法更新多行?多行进度条
Q
多行进度条
5
A
回答
4
最好的方法是使用一些现有的库,如ncurses。但是,您可以通过系统调用清除控制台来尝试肮脏的解决方法:system("cls");
。
2
您可以使用VT100 codes将光标重新定位到更高的行上,然后使用更新的状态对其进行透视。
1
Curses库为控制台UI提供了强大的控制。
3
如果您使用Python尝试使用blessings。这是一个非常直观的诅咒包装。
简单的例子:
from blessings import Terminal
term = Terminal()
with term.location(0, 10):
print("Text on line 10")
with term.location(0, 11):
print("Text on line 11")
如果你真正想实现一个进度条,可以考虑使用 progressbar。它会为您节省很多\r
cruft。
你实际上可以将祝福和进度条连接在一起。仅Windows
import time
from blessings import Terminal
from progressbar import ProgressBar
term = Terminal()
class Writer(object):
"""Create an object with a write method that writes to a
specific place on the screen, defined at instantiation.
This is the glue between blessings and progressbar.
"""
def __init__(self, location):
"""
Input: location - tuple of ints (x, y), the position
of the bar in the terminal
"""
self.location = location
def write(self, string):
with term.location(*self.location):
print(string)
writer1 = Writer((0, 10))
writer2 = Writer((0, 20))
pbar1 = ProgressBar(fd=writer1)
pbar2 = ProgressBar(fd=writer2)
pbar1.start()
pbar2.start()
for i in range(100):
pbar1.update(i)
pbar2.update(i)
time.sleep(0.02)
pbar1.finish()
pbar2.finish()
相关问题
- 1. 多进度条
- 2. 使用多个tqdm进度条进行多处理
- 3. 多个JQuery UI进度条
- 4. 多色进度条Android
- 5. 多个ajax jsonp进程的进度条
- 6. 进度条继续运行
- 7. 进度条并行的foreach
- 8. 当进度条运行
- 9. Backgroundworker,未运行进度条
- 10. 命令行的进度条
- 11. 进度条未显示进度条
- 12. 如何对进度条进行操作
- 13. 设置进度,进度条
- 14. 减慢进度条进度
- 15. 进度条更新进度
- 16. 如何进度进度条
- 17. 进度条宽度
- 18. 不同长度的多个python渐进式进度条
- 19. 进度条ncurses
- 20. Android .....进度条
- 21. css进度条
- 22. GWT进度条
- 23. php进度条?
- 24. 进度条ICS
- 25. 进度条
- 26. jQuery进度条
- 27. PHP进度条
- 28. 进度条
- 29. LWUIT进度条
- 30. 进度条[C++]
是系统( “CLS”):尝试运行呢? – yodie 2009-11-13 04:52:01
在Linux上有“清除” – doc 2009-11-13 04:57:04
OS X怎么样? – yodie 2009-11-13 05:05:02