Полоса загрузки на Python 3.x

Хочу сделать полосу загрузки на подобии как в apt на Linux при скачивании файлов пакетов или их установке.
Там как то надо стирать строки, искал об этом, но многие скрипты не работали почему-то.


Ответы (4 шт):

Автор решения: Pavel Durmanov
In [1]: from tqdm import tqdm

In [2]: import time

In [3]: for i in tqdm(range(10)):
   ...:     time.sleep(2)
   ...:
 30%|██████████████████████████████▌                                                                       | 3/10 [00:06<00:14,  2.00s/it]
→ Ссылка
Автор решения: Manul74

Код не мой а стыреный из инета которым я пользуюсь. Без доп библиотек 1 функция

import time
def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\r"):
    """
    Call in a loop to create terminal progress bar
    @params:
        iteration   - Required  : current iteration (Int)
        total       - Required  : total iterations (Int)
        prefix      - Optional  : prefix string (Str)
        suffix      - Optional  : suffix string (Str)
        decimals    - Optional  : positive number of decimals in percent complete (Int)
        length      - Optional  : character length of bar (Int)
        fill        - Optional  : bar fill character (Str)
        printEnd    - Optional  : end character (e.g. "\r", "\r\n") (Str)
    """
    percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
    filledLength = int(length * iteration // total)
    bar = fill * filledLength + '-' * (length - filledLength)
    print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = printEnd)
    # Print New Line on Complete
    if iteration == total:
        print()
# A List of Items
items = list(range(0, 57))
l = len(items)
# Initial call to print 0% progress
printProgressBar(0, l, prefix = 'Progress:', suffix = 'Complete', length = 50)
for i, item in enumerate(items):
    # Do stuff...
    time.sleep(0.1)
    # Update Progress Bar
    printProgressBar(i + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50)

→ Ссылка
Автор решения: Даниил Кустов

Лично я делаю вот так(не используя модули):

import time

for percent in range(100):
    s = f"[{(percent // 10) * '■'}"
    s += f"{(10 - (percent // 10)) * '○'}] "
    s += f"{percent}"
    print(s, end="\r")
    time.sleep(0.1)

>>> [■■■■■■■○○○] 78

s разбито на строки чтобы было удобнее читать. На деле все можно собрать в одну строку

→ Ссылка
Автор решения: Андрей

попробуй это

import time

from progress.bar import IncrementalBar

mylist = [1,2,3,4,5,6,7,8]

bar = IncrementalBar('Countdown', max = len(mylist))

for item in mylist:
    bar.next()
    time.sleep(1)

bar.finish()
→ Ссылка