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?
Simple Version. One way is to use the carriage return ( '\r' ) character to return to the start of the line without advancing to the next line.
The new line character in Python is \n . It is used to indicate the end of a line of text. You can print strings without adding a new line with end = <character> , which <character> is the character that will be used to separate the lines.
In Python, the built-in print function is used to print content to the standard output, which is usually the console. By default, the print function adds a newline character at the end of the printed content, so the next output by the program occurs on the next line.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With