# When the file is written annotations hardware, system calls, such I / O operations are typically very long time # To reduce I / O operation frequency, typically using a buffer file (before there is sufficient data for the system call) # File buffering behavior is divided into: # full buffer: buffering open function is provided an integer greater than 1, n, n being the buffer size # line buffer: buffering open function set to 1, as long as the encounter \ n outputs general procedure for the terminal # unbuffered: buffering function is set to zero open to a handle a # Python default number of bytes buffer full 4096 F = open ( " test.txt " , " W " , buffering = 1024) # fully buffered f = Open ( " test.txt " , " W " , buffering =. 1) # line buffer F = Open ( "test.txt", "w", buffering=0) # 无缓冲 f.write("$" * 1024) f.write("abc\n") # 遇到\n就输出 f.write("$") f.close()