0

I want to print such that the new print object replaces the old printed object in the same line. Here is what I do:

for i in range(0,10000): 
     print "\r", i,

However the result that this gives me is this:

9999 1415 

I expect to only see 9999. I do not know why it prints out 1415.

There are people who have given answers on this topic before but they have been focused on python 3.x. I have python 2.7 with Canopy.

Abhinav Kumar
  • 1,613
  • 5
  • 20
  • 33
  • 1
    Do you run it from IDLE? The code above works great if executed from shell. `\b` and `\r` does not work from within idle. See http://stackoverflow.com/questions/19187759/implementing-a-backspace-in-python-3-3-2-shell-using-idle – Fredrik Pihl Jun 19 '14 at 18:21

2 Answers2

0

are you sure? Here is my output in Python 2.7. It works fine

 Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range(0,10000): 
...      print "\r", i,
... 
9999 
>>> 
brain storm
  • 30,124
  • 69
  • 225
  • 393
0

The IDLE console doesn't support \r to overwrite characters that have been printed. Such techniques will work if you run python from shell.

Same case with \b too. There is nothing wrong in your program.

user3218088
  • 253
  • 3
  • 10