How can I show infinite dots ("...") in a while loop

Is it possible to show something like this in Python?

Checking.

Check ..

Checking ...

Checking.

I want it to only display one line while the script is running, but stop when it's done. script I want to add it here: https://github.com/brandonusher/Python-Scripts/blob/master/check_port.py

+3


source to share


1 answer


Print the text without the newline character, then run the flush stdout command. Print a \r

so that the cursor goes back to the beginning of the line. Repeat until the end. Don't forget to overwrite the existing text.



while True:
  sys.stdout.write('\rfoo.  ')
  sys.stdout.flush()
  delay(100)
  sys.stdout.write('\rfoo.. ')
  sys.stdout.flush()
  delay(100)
  sys.stdout.write('\rfoo...')
  sys.stdout.flush()
  delay(100)

      

+8


source







All Articles