Python Forum

Full Version: On the spot counter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
What OS are you using?
In my Win10 console everything works as intended.
use:
>>> import time
>>> for i in range(15):
...     time.sleep(1)
...     print(f"{i} ", end='\r')
... 
>>>
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.
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.
I also do _not_ see any different pause after 6. I am using spyder from Anaconda Navigator run on Win7.
That´s a problem with Spyder console.
Don´t restrict yourself just to this IDE, try different ones.
(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.
[/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?
(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
Pages: 1 2