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 in. getpass()
does not show what the user typed, but it does preserve the "Password:" prompt.
To fix this, I would like to only remove the last line (which would remove the newline from the end of the line as well).
system('cls') to clear the screen. The output window will print the given text first, then the program will sleep for 4 seconds and then screen will be cleared and program execution will be stopped.
Approach. By default, Python's print statement ends each string that is passed into the function with a newline character, \n . This behavior can be overridden with the function's end parameter, which is the core of this method. Rather than ending the output with a newline, we use a carriage return.
You might be able to do what you want with VT100 control codes.
Something like this maybe:
CURSOR_UP_ONE = '\x1b[1A' ERASE_LINE = '\x1b[2K' print(CURSOR_UP_ONE + ERASE_LINE)
Give this a try:
CURSOR_UP = '\033[F' ERASE_LINE = '\033[K' print(CURSOR_UP + ERASE_LINE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With