【问题标题】:Python print to the end of the windowPython 打印到窗口末尾
【发布时间】:2016-12-20 23:02:14
【问题描述】:

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

我正在使用冲洗动态打印。一个 sn-p 的代码是:

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

除了我想要“完成”。不管窗口有多大,都要一直打印到行尾。

【问题讨论】:

    标签: python printing styles pretty-print user-friendly


    【解决方案1】:

    这会找到控制台窗口的长度,然后生成一串空格,最后是Done.。

    import os
    rows, columns = os.popen('stty size', 'r').read().split()
    spaces = ''.join([' '] * (int(columns) - 5))
    done = spaces + 'Done.'
    print(done)
    

    【讨论】:

    • 关闭,但我知道为什么它不完美。在 (int(colums) - 5)) 部分中,它没有考虑初始字符串或点的大小。所以应该是 (int(colums) - 5 - 17 - 3)
    猜你喜欢
    • 2023-02-05
    • 1970-01-01
    • 2014-11-02
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多