【问题标题】:Python console application - output above input linePython 控制台应用程序 - 输入行上方的输出
【发布时间】:2012-12-27 08:07:37
【问题描述】:

我正在尝试用 Python3 编写控制台应用程序。

问题是我希望所有输出消息 EG: print("Status message") 都位于底部输入行的上方。

Status message 1
Status message 2
Status message 3
Console:> I want to type here while the output messages displayed

现在看起来更像这样

Console:>  want to type here while the outStatus message 1
put messages displayed

有没有不使用诅咒的方法?

【问题讨论】:

    标签: python input console output curses


    【解决方案1】:

    试试这个:

    print chr(27)+'[2AOutput'
    

    希望这是您的要求。

    抱歉,以上内容适用于 Python 2.7。我不确定是否是 Python 3 版本

    print(chr(27)+'[2AOutput')
    

    行不通。

    参考: http://en.wikipedia.org/wiki/ANSI_escape_code

    【讨论】:

    • 这将删除积压输出的功能。如果您希望保留该功能,您可以执行以下操作: print('\e[A\e[kOutput\nCurrent state of the prompt', end='') \e[A 将光标移动到最后打印的字符串 (应该是Console:>...)。 \e[k 清除该行,然后用新输出替换它,然后重新打印Console:>... 并准备从输入中接收更多值。有可能应该跳过\e[A
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2011-03-10
    • 2013-07-13
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多