Reputation: 132
I am trying to use time.sleep() to pause in between print statements.
import time
def test():
print("something", end="")
time.sleep(1)
print(" and ", end="")
time.sleep(1)
print("something")
When I use the end argument, the code waits before it starts to print. It should print, wait, print, wait, and print ("something, wait, and, wait, something"). However, when I use the end argument, it waits, and prints "wait something and something". This code works as I wanted it to without the end argumets.
Upvotes: 1
Views: 429
Reputation: 177600
Your output device is line-buffered and only flushes when a new line is output. Add flush=True
as an additional parameter to print
to force a flush to the output.
Upvotes: 4