Why doesn't sys.stdout.write('\b') backspace against newlines?
Compare:
for item in range(0, 5):
sys.stdout.write('c')
for item in range(0, 5):
sys.stdout.write('\b')
开发者_开发知识库
Works as you would imagine, but:
for item in range(0, 5):
sys.stdout.write('\n')
for item in range(0, 5):
sys.stdout.write('\b')
still leaves you with five newline characters. Any ideas?
It may seem reasonable today to expect backspace to be able to work over newline characters, on a console but that would not be backward compatible with teletypes as there is no reverse linefeed.
This is about the behavior of console windows: backspaces only work within a line, they won't backup over newlines.
This is absolutely nothing to do with Python. It's your console driver that handles any visual effects. Most of them will emulate an ASR33 teletype ... backspace means move the print head one space back towards the start-of-line position, if possible.
精彩评论