user8751232
user8751232

Reputation: 49

Progress bar not working?

import time

for i in range(100):
  print('*',end='')
  time.sleep(0.1)

why this code is not working for showing progress? Expected output was to be showing a progress '****************'.

Upvotes: 0

Views: 638

Answers (1)

John Anderson
John Anderson

Reputation: 38857

Stdout is buffered. You can flush it with a call to sys.stdout.flush() after each print. Or you can add flush=True to your print command instead of doing an explicit flush:

print('*', end='', flush=True)

Upvotes: 1

Related Questions