In Python, why won't something print without a newline?

后端 未结 6 2355
轮回少年
轮回少年 2020-12-17 15:53
import time
import sys
sys.stdout.write(\"1\")
time.sleep(5)
print(\"2\")

will print \"12\" after 5 seconds

import time
import sys
         


        
6条回答
  •  清酒与你
    2020-12-17 16:23

    Because stdout is buffered. You may be able to force the output sooner with a sys.stdout.flush() call.

提交回复
热议问题