Print correctly on the console

When I write a script that updates the printed line, for example, for example:

for i in range(101):
    print(str(i) + "% \r", end="")

and run this script using terminal (Ubuntu), I get the correct output, which updated the line:

100%

However, using Pydev in Eclipse, the Eclipse console does this:

0%
1%
2%
...
100%

Does anyone know how to fix this? Thanks in advance!

+2
source share
2 answers

This is apparently an old CR LF problem. Depending on the OS and the console used, CR and LF will be interpreted differently as line terminations.

Some systems require CRLF as the end of a line. Some systems require only LF, but CR is implicit. Some systems (like yours) do LF implicitly before each CR, although this is the first time I see it.

, PyDev.

EDIT: escape- ANSI . CSInD n CSInC n .

0

, 'print' , \r , sys.stdout :

import time, sys

for i in range(101):
    sys.stdout.write(str(i) + "% \r")
    sys.stdout.flush()
    time.sleep(.3)
+3

All Articles