您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python:-u选项的意义?

Python:-u选项的意义?

来自python --help

-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'

手册页指出:

-u     Force  stdin,  stdout and stderr to be totally unbuffered.  On

systems where it matters, also put stdin, stdout and stderr in binary mode. Note that there is internal buffering in xreadlines(), readlines() and file-object iterators (“for line in sys.stdin”) which is not influenced by this option. To work around this, you will want to use “sys.stdin.readline()” inside a “while 1:” loop.

Python以缓冲模式打开stdin,-out和-error流;它会读取或写入更大的块,将数据保留在内存中,直到达到阈值为止。-u禁用这些缓冲区。

此外,python可以解释打开文件上的换行符,并将它们与本机平台换行符进行相互转换(文本模式)。该-u选项禁用此转换,使您可以处理二进制数据,而不必担心\r\n组合可能会发生什么。使用此功能打开文件时,相当于使用rbwb模式open()

python 2022/1/1 18:42:48 有267人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶