The optional buffering argument specifies the file’s desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size. A negative buffering means to use the system default, which is usually line buffered for tty devices and fully buffered for other files. If omitted, the system default is used.
python中的文件I/O已经被缓冲。使用^{} function 可以确定缓冲的扩展写入:
就我个人而言,我会通过
with
语句将该文件用作上下文管理器。当with
套件下的所有语句(至少一个缩进级别更深)完成或时,将引发异常,文件对象将关闭:在上面的例子中,我将缓冲区设置为20MB。
相关问题 更多 >
编程相关推荐