remove last STDOUT line in Python

后端 未结 5 752
温柔的废话
温柔的废话 2020-11-28 11:17

I am trying to figure out how to suppress the display of user input on stdout.

raw_input() followed by any print statement preserves what the user typed

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 11:34

    I am not entirely sure if this works: maybe you could, just before calling raw_input(), replace sys.stdout with your self-defined file-like object which swallows the output. Right after that, you could set sys.stdout back to what it has been before.

    Edit: looks like this approach does not work, because whatever the user types in stays on the screen.

    Another option for console manipulation and direct keyboard control is curses.

提交回复
热议问题