Why Python IDLE Print Instead Of Backspace? [duplicate]

∥☆過路亽.° 提交于 2019-12-20 07:36:02

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/42380959/why-python-idle-print-instead-of-backspace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!