On Tue, 9 Jan 2018 08:39:06 -0800 Nathaniel Smith <njs@pobox.com> wrote:
On Jan 9, 2018 04:12, "Random832" <random832@fastmail.com> wrote:
On Tue, Jan 9, 2018, at 05:46, Nick Coghlan wrote:
If you view them as comparable to subprocess pipes, then it can be surprising that they're not iterable when using a line-oriented protocol.
If you instead view them as comparable to socket connections, then the lack of iteration support seems equally reasonable.
Sockets are files - there's no fundamental reason a stream socket using a line-oriented protocol (which is a common enough case), or a datagram socket, shouldn't be iterable. Why aren't they?
Supporting line iteration on sockets would require adding a whole buffering layer, which would be a huge change in semantics.
The buffering layer already exists. Just call socket.makefile() and you've got your iterable object :-) https://docs.python.org/3/library/socket.html#socket.socket.makefile Regards Antoine.