Reading line-by-line on a socket

sik0fewl xxdigitalhellxx at
Thu Mar 13 22:12:21 CET 2003

sik0fewl wrote:
> Hey,
> Is there any way to read line by line on a socket, without having to 
> recv() a chunk and the keep it in some sort of queue to retrieve later?
> The reason this doesn't work for me is because I would like select() to 
> still be able to detect that there is data waiting to be read from the 
> socket. If all else fails I'll just have to do a loop through the 
> incoming queue after my socket has data to be read.
> In short, I want a readline() for a socket.
> Any suggestions?

Sorry for the stupid quesetion...

I tried makefile()/readline() in Pythonwin before I messages this group 
and it crashed Pythonwin so I assumed that it wasn't possible this way. 
After trying it in the interpreter run from the command line it works fine:

import socket
s = socket.socket(AF_INET, SOCK_STREAM)
s.connect(("localhost", 80))
x = s.makefile("rb")
s.write ("HEAD ...")
print x.readline()


More information about the Python-list mailing list