-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
  • 31,685
  • 30
  • 101
  • 155
M. Thompson
  • 95
  • 11

1 Answers1

1

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

print("waiting ...", end=" ", flush=True)
user2357112
  • 235,058
  • 25
  • 372
  • 444