我知道要在命令行上更新類似進度條的東西,可以使用'\ 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