Sublime Forum

Incorrect behaviour printing \r

#1

Hi,

SublimeText 3 fails to print ‘\r’ (carriage return) in Python:
import sys

for i in range(10):
    sys.stdout.write("\r%i" % i)
    sys.stdout.flush()

instead of

0123456789

it produces:

0
1
2
3
4
5
6
7
8
9
0 Likes

#2

The reason for this is that Sublime normalizes line endings internally to \n for display in buffers and panels (such as the build output). In the case of a regular file that’s not an issue because it will be saved back with the appropriate line endings.

However in the build output the consequence of this is that you can’t output partial lines. More information on the details of this is available here.

0 Likes