gpt4 book ai didi

python - 为什么 Python 2.x 的 write() 函数不返回写入的字节数?

转载 作者:太空宇宙 更新时间:2023-11-04 06:21:01 26 4
gpt4 key购买 nike

我最感兴趣的是导致 Python 2.x 的 write() 函数返回 None 而不是写入的字节数的设计决策。这意味着 File 对象有一些不同的心智模型——它不仅仅是 UNIX 文件描述符的轻量级包装器。

这是我所指的文档:http://docs.python.org/library/stdtypes.html#file.write

最佳答案

来自Python官方手册3.2.2:-

write(b) 

Write the bytes or bytearray object, b and return the number of bytes written. When in non-blocking mode, a BlockingIOError is raised if the buffer needs to be written out but the raw stream blocks.

关于python - 为什么 Python 2.x 的 write() 函数不返回写入的字节数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12184101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com