Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
On the spot counter
#1
I would like to display a count in the Console such that each increment is replaced in the same place (at start of line) by the next.
Having looked at posts on overwriting the last line, I thought this should work ok, but it adds each increment to the last line instead of replacing it

import time
for i in range (15):
    time.sleep(1)
    print(i, end="\r")
result is:
1234567891011121314
note also that when it gets to 6 there is a long gap to 7:
123456 7

What am I doing wrong?

Many thanks
Astrikor
Reply
#2
What OS are you using?
In my Win10 console everything works as intended.
Reply
#3
use:
>>> import time
>>> for i in range(15):
...     time.sleep(1)
...     print(f"{i} ", end='\r')
... 
>>>
Reply
#4
ThomasL:
I'm using Win7 with Python 3.7.4

Larz60+:
Thanks, but that gives same result i.e a horizontal row of concatenated i values as in my query.
Reply
#5
When you say console i guess you mean IDLE?
IDLE does not support backspace,carriage-return,form-feed or ANSI escape sequences.
If you run from command line(cmd) it will work,or eg cmder as i use.
[Image: riru29.png]
IDLE is not so good,and is usually only used bye new users for while.
Reply
#6
I also do _not_ see any different pause after 6. I am using spyder from Anaconda Navigator run on Win7.
Reply
#7
That´s a problem with Spyder console.
Don´t restrict yourself just to this IDE, try different ones.
Reply
#8
(Nov-27-2019, 09:54 PM)snippsat Wrote: When you say console i guess you mean IDLE?
IDLE does not support backspace,carriage-return,form-feed or ANSI escape sequences.

Thanks snippsat - yes, I am using IDLE - so that's the answer then.

I'll try something else - how about Pycharm-community-2019.2.5 ?

Thanks again.
Reply
#9
[/quote]
how about Pycharm-community-2019.2.5 ?
[/quote]

Oh no! Pycharm doesn't do the job either - it shows blank until it hits the last count value.

cmd does work, but is clunky to run a file.

I would rather run from an IDE.

Any other ideas?
Reply
#10
(Nov-28-2019, 09:54 AM)Astrikor Wrote:
(Nov-27-2019, 09:54 PM)snippsat Wrote: When you say console i guess you mean IDLE?
IDLE does not support backspace,carriage-return,form-feed or ANSI escape sequences.

Thanks snippsat - yes, I am using IDLE - so that's the answer then.

I'll try something else - how about Pycharm-community-2019.2.5 ?

Thanks again.

I tried in Pycharm, we are getting result but not immediate atleast half a second it is taking
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020