Search code examples
pythonpython-3.xbackspace

Why Python IDLE Print Instead Of Backspace?


I'm a high school student in Korea.

While programming in python, I want to implement 'ghost typing', so I wrote this code on python IDLE.

for i in range(5):
    print(i+1, end='')
    time.sleep(0.05)
    print('\b', end='')

But it displayed:

12345

Image - This char() isn't displayed here.

So I wonder, why python IDLE print '', and what I should do to print 'backspace' normally?

This is in python 3.5.3(with windows 10), 3.6.0(with windows 7).

p.s. This code in python console, It print nothing.


Solution

  • IDLE doesn't support backspace characters,

    No, IDLE does not support backspace, nor carriage-return, nor formfeed, nor ANSI escape sequences.

    You are expecting \b to move the cursor one cell to the left in IDLE's interactive shell window. It doesn't do that. IDLE does not support cursor addressing in its shell window, with the exception of newline and tab.

    source

    Additionally, you're using range() but then you're adding one to i. You could simplify it by specifying a start and an end range, range(1, 6) so it'll output 1,2,3,4,5 instead.