-3

I'd like to print an update on what's processing, then process it, then print a 'done' statement. The code below prints "waiting ... done" after the 2 second sleep finishes. How can I get the first print statement to execute before the code between the print statements executes?

import time
print("waiting ...", end=" ")
time.sleep(2)
print("done")
Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
M. Thompson
  • 95
  • 11

1 Answers1

1

It's buffered. You need to flush the buffer:

print("waiting ...", end=" ", flush=True)
user2357112
  • 260,549
  • 28
  • 431
  • 505