How to remove lines from stdout in Python - in SciTe, Idle, Eclipse or other editor with console

前端 未结 1 1003
星月不相逢
星月不相逢 2021-01-25 01:46

For a standard Python Console window, you can remove the last line with for example sys.stdout.write(\'\\r\'+\' \'*len(line)) as I explained here.

But for e

1条回答
  •  孤独总比滥情好
    2021-01-25 02:05

    I am comming to the conclusion that it is not possible, please correct me if I am wrong.

    Python Console Window (terminal) does not 'flush' the written line until the next line is passed, as if it keeps a carriage returns like '\n' in memory that can be ignored when writing('\r). The other, more GUI based console windows (IDE's) are obviously implemented differently. So perhaps it could be a feature request to interprete '\r' to erase a previous line in these consoles, so that all consoles share at least a common behaviour to the standard console, only perhaps with additional options.

    A solution meanwhile for me as user could be to change the sys.stdout to a new console window, which is questioned before, but answered unsatisfactory... Anybody evolved a bettor opinion to this?

    Or use something like the curses module, but than for Windows (is there a 'curses.py' for Windows?), e.g. Console.py.

    0 讨论(0)
提交回复
热议问题