-1

I need:

  • Dynamically in-place display some string in terminal while my script is running. Similar to how 'tqdm' package shows progress bar in-place in terminal.

I do NOT need:

  • display progress bar
  • use huge bloated frameworks to build GUI (Graphical Interfaces), etc.

What I want to see in terminal (example):

Requests per minutes: 15

What is the simplest way to show some text in-place? I am fine to use the 'tqdm' package if it can do what I described.

Nairum
  • 1,217
  • 1
  • 15
  • 36

1 Answers1

0
import sys
import time

for x in ('1234','56','789'):
    sys.stdout.write('Requests per Minute: {0:20s}\r'.format(x))
    sys.stdout.flush()
    time.sleep(1)
sys.stdout.write('\n')

The carriage return \r returns the cursor to the beginning of the line. The extra spaces are needed to overwrite previous output.

  • Thanks, but your code shows nothing in terminal. For example, when I run 'tqdm', I can see real time updates in-place in my terminal. But your code is useless unless I will find how to show `stdout` in terminal in-place in real time. Now the code prints nothing to nowhere. – Nairum Apr 13 '22 at 13:42
  • @Nairum I just tested again and the code I posted works for me on Linux and Windows. – Acmeist0815 Apr 13 '22 at 13:56