There are several folks on here looking for backspace answers in Python. None of the questions I have searched have answered this for me, so here goes:
The Simple Goal: be able to print out a status string on one line, where the next status overwrites the first. Similar to a % complete status, where instead of scrolling a long line of 1%\n, 2%, ... etc. we just overwrite the first line with the newest value.
Now the question. When I type this in idle: print("a\bc")
I get this as output: ac
with what looks like an odd box with a circle between the 'a' and 'c'. The same thing happens when using sys.stdout.write()
.
Is this an Idle editor setting/issue? Does anyone even know if what I am trying is possible in the Idle Shell?
Thanks for any insight.
PS: Running Python 3.3.2 Idle on Windows 7, 64-bit system.
EDIT: Copying the output in Notepad++ is revealing that Python is printing out a 'backspace' character, and not actually going back a space. Perhaps what I am trying to accomplish is not possible?
This doesn't answer your question in a literal fashion, but I think it might be useful to point out that generally interfaces like the one where you are describing (e.g., where one part of the screen is continuously updated, without newlines), it just generally implemented using a library like ncurses.
Python has a curses library built-in (http://docs.python.org/3.3/library/curses.html), which can more or less achieve your end goal.
Edit:
Apparently the carriage return
\r
and the backspace\b
won't actually work within Idle because it uses a text control that doesn't render return/backspace properly.You might be able to write some sort of patch for Idle, but it might be more trouble than it's worth (unless you really like Idle)