0

试图弄清楚如何在风格上打印“完成”。在窗口的尽头。

我正在使用冲洗动态打印。一段代码将是:

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

除了我想要“完成”。无论窗口有多大,都要一直打印在行尾。

4

1 回答 1

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)
于 2016-12-20T23:54:59.733 回答