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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.