实际案例

将文件内容写入到硬件设备时,使用系统调用,这类I/O操作的时间很长。为了减少I/O操作的次数,文件通常使用缓冲区,当有足够多的数据时才进行系统调用。文件的缓冲行为,分为全缓冲、行缓冲和无缓冲。

文件缓冲 分为全缓冲(硬盘 缓冲大小满了,就落盘),行缓冲(tty),无缓冲(串口)

全缓冲 : open函数的buffering设置大于1的整数n,n为缓冲区大小 linux默认为page的大小4096 满了n 个字节才会落盘
# mac os 系统不是的

行缓冲 : open 函数的buffering设置为1 f=open("demo.txt",'w',buffering=1) 碰到换行就会将缓冲区落盘

无缓冲 : open 函数的buffering设置为0 f=open("demo.txt",'w',buffering=0) 时时落盘到硬盘

"""
From open's docstring:

... buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode) ...
So change inFile = open(WORDLIST_FILENAME, 'r', 0)

to

inFile = open(WORDLIST_FILENAME, 'r'), or to

inFile = open(WORDLIST_FILENAME, 'rb', 0) if you really need it (which I doubt).
"""

HTTPX 基础教程-新乡seo|网站优化,网站建设_微信公众号:zeropython—昊天博客