M
M
MichaelMih2021-02-06 01:03:53
Python
MichaelMih, 2021-02-06 01:03:53

Python how to output dynamic text?

Hi all! I want to do it using the example of loading in the console:
loading [|||||...]
loading [||||||..]
and I need to do it so that it's all in one line, and not every time with a new one lines.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Nevzorov, 2021-02-06
@MichaelMih

As an option - use the library rich: https://pypi.org/project/rich/
5ZyL3VD.gif

A
Alexander, 2021-02-06
@shabelski89

I like the tdqm library, a 3 line progress bar is added.
https://tqdm.github.io/

S
shurshur, 2021-02-06
@shurshur

Something like this:

import time
  
def progressbar(size=10):
  for i in range(size+1):
    bar = "|"*i+"."*(size-i)
    print (f"\r[{bar}]", end='')
    time.sleep(1)
  print ()

progressbar()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question