Delete the last input row in Python

console, input, python

Solution

This will work in most unix and windows terminals ... it uses very simple ANSI escape.

num = int(raw_input("input number: "))
print "\033[A                             \033[A"    # ansi escape arrow up then overwrite the line

Please note that on Windows you may need to enable the ANSI support using the following http://www.windowsnetworking.com/kbase/windowstips/windows2000/usertips/miscellaneous/commandinterpreteransisupport.html

"\033[A" string is interpreted by terminal as move the cursor one line up.

Problem

I have the following code: ``` num = int(raw_input("input number: ")) print "\b" * 20 ``` The console output looks like ``` input number: 10 ``` I'd like to delete the text `input number: 10` after the user presses `ENTER`. The backspace key `\b` can't do it.

Original source