-1
import datetime

a = 100
b = 0 
while a > b:
     print(str(datetime.datetime.now()), end="\r")
     b += 1
     print(b)

I don't know why this doesn't work, i've searched a lot and everyone does this like this but it doesn't work for me, im confused!

What i want to achieve is to overwrite the print and print in the same line without making a ton of lines.

instead of this:

1

2

3

i wanted this:

1 and on the next print it would only appear 2 and next only 3 and etc..

Tiago Oliveira
  • 47
  • 1
  • 12

2 Answers2

0

previously answered but summarized here:

import sys 

while a > b: 
    print('\r')
    # delay for readability
    print('your statement')
    sys.stdout.flush()
ml_dave
  • 23
  • 5
0

You need this I believe! as per Python 3.x

Please read the document - here

Also, refer to this question - how to overwrite stdout

import datetime

a = 100
b = 0 
while a > b:
     print(str(datetime.datetime.now()), end="\r")
     b += 1
     print(b, end = '\r')

OR

for x in range(10):
    print('{0}'.format(x), end = '\r')
print(end='\r')