print函数中的flush
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
简单说就是将缓存里面的内容立即输出到标准输出流(这里是sys.stdout, 也就是默认的显示器)
这个功能在客户端脚本几乎用不上, 大多用于服务器端
比如反向Ajax里面就要用到flush, 举个例子: 在线web聊天页面会实时显示聊天的内容, 其实后台是一直在向服务器请求数据的, 正常情况下是请求完毕之后才会输出相应内容, 但是是即时聊天, 需要一有相应就得立即返回, flush也就起作用了
浙公网安备 33010602011771号