Python print to the end of the window

637 views Asked by At

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.

1

There are 1 answers

1
Navidad20 On

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)