Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Python 2.x's write() function return the number of bytes written?

Tags:

python

I'm most interested in the design decision that led to Python 2.x's write() function returning None instead of the number of bytes written. It would imply some different mental model for the File object -- that it's not just a lightweight wrapper around a UNIX file descriptor.

Here's the documentation I'm referring to: http://docs.python.org/library/stdtypes.html#file.write

like image 359
slacy Avatar asked Nov 29 '25 02:11

slacy


1 Answers

From Python official Manual 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.

like image 197
perilbrain Avatar answered Dec 02 '25 05:12

perilbrain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!