G
G
gylah-u2021-10-04 00:36:34
Python
gylah-u, 2021-10-04 00:36:34

How to make dynamic text in python terminal?

How can I make text dynamic without using third party modules other than the built-in ones?
for example

[███...] 
[████..]
[█████.]
[██████]

And so that it is in one line and changes, for example, after a second.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2021-10-04
@saboteur_kiev

Print carriage return (\r) without line feed

from time import sleep
import sys

for i in range(11):
    sys.stdout.write('\r')
    sys.stdout.write("[%-10s] %d%%" % ('='*i, 10*i))
    sys.stdout.flush()
    sleep(0.25)

A
Alexander Karabanov, 2021-10-04
@karabanov

Tracking Progress in Python

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question