[Python-ideas] make Connections iterable
solipsis at pitrou.net
Tue Jan 9 11:49:23 EST 2018
On Tue, 9 Jan 2018 08:39:06 -0800
Nathaniel Smith <njs at pobox.com> wrote:
> On Jan 9, 2018 04:12, "Random832" <random832 at 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 :-)
More information about the Python-ideas