0

Trying to figure out how to stylistically print "Done." at the end of the window.

I am printing dynamically using flush. A snippet of code would be:

print("Opening the file "),
sys.stdout.flush()
for i in range(3):
    print("."),
    sys.stdout.flush()
print("\tDone.")

Except I would like "Done." to be printed all the way at the end of the line no matter how big the window is.

Shaw
  • 169
  • 1
  • 3
  • 12

1 Answers1

0

This finds the length of the console window, then makes a string of spaces, with Done. at the end.

import os
rows, columns = os.popen('stty size', 'r').read().split()
spaces = ''.join([' '] * (int(columns) - 5))
done = spaces + 'Done.'
print(done)
Navidad20
  • 832
  • 7
  • 11
  • Close but I figured out why it wasn't perfect. in the section (int(colums) - 5)) it doesnt take into account the size of the initial string or the dots. so it should be (int(colums) - 5 - 17 - 3) – Shaw Dec 21 '16 at 17:55