Implementing a backspace in Python 3.3.2 Shell using Idle

若如初见. 提交于 2019-11-27 19:07:11

问题


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?


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/19187759/implementing-a-backspace-in-python-3-3-2-shell-using-idle

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