我正在使用progressbar2库以显示文件下载的进度条。
我想在进度条行下方(或上方)的行中打印出当前下载文件的名称,并将每个文件名打印在同一行。
import progressbar
format_custom_text = progressbar.FormatCustomText(
'Downloading file:%(f)s',
dict(
f='',
),
)
bar = progressbar.ProgressBar(widgets=[
progressbar.Counter(format='[%(value)02d/%(max_value)d]'),
progressbar.Bar(marker=u'\u2588', fill='.', left='|', right='|'),
format_custom_text])
for i in bar(range(len(files))):
format_custom_text.update_mapping(f=files[i])
client.download_file(file_path=files[i])
示例:
[25/64] |███████████████████████............................| Downloading file: dummyfile.txt
我想要的是更改文件名,并仍将其打印在进度条下的同一行上。
[25/64] |███████████████████████............................|
Downloading file: dummyfile.txt
答案 0 :(得分:0)
这在终端上对我有用:
import time
import progressbar
format_custom_text = progressbar.FormatCustomText(
'\nDownloading file:%(f)s\033[F',
dict(
f='',
),
)
bar = progressbar.ProgressBar(widgets=[
progressbar.Counter(format='[%(value)02d/%(max_value)d]'),
progressbar.Bar(marker=u'\u2588', fill='.', left='|', right='|'),
format_custom_text])
files=list(range(1000))
for i in bar(range(len(files))):
format_custom_text.update_mapping(f=files[i])
time.sleep(0.1)