[issue25174] Backspace Escape Character at End of String

Martin Panter report at bugs.python.org
Sat Sep 19 06:00:34 CEST 2015


Martin Panter added the comment:

Python itself doesn’t treat backspace specially. What you are probably seeing is the terminal interpreting the backspace specially by moving the cursor left (without erasing anything).

>>> s = "12345" + '\b' + '6'
>>> s
'12345\x086'
>>> s[5]  # ASCII code for backspace is 0x08
'\x08'

If you redirect the output to a file or other program, you will also see the backspace code is still there:

$ python2 -c 'print "12345" + "\b" + "6"' | hexdump -C
00000000  31 32 33 34 35 08 36 0a                           |12345.6.|
00000008

----------
components:  -Regular Expressions
nosy: +martin.panter
resolution:  -> not a bug
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25174>
_______________________________________


More information about the Python-bugs-list mailing list