开发者

Python's print function that flushes the buffer when it's called? [duplicate]

开发者 https://www.devze.com 2023-01-19 12:55 出处:网络
This question already has answers here: Disable output b开发者_开发百科uffering (16 answers) Closed 17 days ago.
This question already has answers here: Disable output b开发者_开发百科uffering (16 answers) Closed 17 days ago.

I have the following code to flushing out the output buffer.

print('return 1')
sys.stdout.flush()

Can I set up the print function so that it automatically flushes the buffer when it's called?


You can start python in unbuffered mode using the -u flag, e.g.

python -u script.py

or

#!/usr/bin/env python -u

as "shebang" header for your script.

0

精彩评论

暂无评论...
验证码 换一张
取 消